Solved

String autocompletion with the PropertyGrid

Posted on 2009-05-19
2
1,326 Views
Last Modified: 2012-05-07
Hi,

I'm desesperately looking for a way to implement the autocompletion (predictive value) in the text box of a PropertyGrid control. I want to type my text and get a the same time a possible value to complete the field.

I know how to set a combobox with a set of possible values but this not what i'm looking for. The value entered by the user (always a string) is not always existing in the list of possible values.

Here is the hack i've found, unfortunatly it sets the autocompletion on all fields in my property grid. I look for the possibility to put a different set of possible values by property.

Thanks for your help!
            Dim stringCollection As AutoCompleteStringCollection = New AutoCompleteStringCollection()
            stringCollection.Add("value1")
            stringCollection.Add("value2")
            stringCollection.Add("value3")
 
            SetPropertyGridAutocompletion( _
                                Me.NodeExtendedDataPropertyGrid, _
                                stringCollection)
 
     Private Sub SetPropertyGridAutocompletion( _
                ByVal propertyGrid As System.Windows.Forms.PropertyGrid, _
                ByVal stringCollection As AutoCompleteStringCollection)
 
        Dim propertyGridView As Control = propertyGrid.Controls(2) 'Get reference to property grid view
        Dim propertyGridViewType As Type = propertyGridView.GetType() 'get the type
        Dim pgType As Type = propertyGridViewType 'set this to a local variable
        Dim info As FieldInfo = pgType.GetField("edit", BindingFlags.Instance Or BindingFlags.NonPublic)
 
        ' Get the fieldInfo,which holds the reference to the textbox
        Dim txtBox As TextBox = CType(info.GetValue(propertyGridView), TextBox) 'Cast it to the textBox
 
        txtBox.AutoCompleteCustomSource = stringCollection
        txtBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend
        txtBox.AutoCompleteSource = AutoCompleteSource.CustomSource
 
    End Sub

Open in new window

0
Comment
Question by:stevenhackars
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
ID: 24429840
You need to implement a new type editor for your property:

http://www.codeproject.com/KB/miscctrl/bending_property.aspx
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question