Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1367
  • Last Modified:

String autocompletion with the PropertyGrid

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
stevenhackars
Asked:
stevenhackars
1 Solution
 
Alexandre SimõesManager / Technology SpecialistCommented:
You need to implement a new type editor for your property:

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now