Solved

String autocompletion with the PropertyGrid

Posted on 2009-05-19
2
1,268 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now