DataSource question

rickyd

Member
Joined
Dec 12, 2004
Messages
10
Location
Brisbane
Programming Experience
10+
Hello all.

I am developing an autocomplete combo box control to use in my apps which I will publish for free when it's done.

I have all the functionality I need like turning autocomplete on and off,
change the font and forecolor.

The last hurdle I have come up against is getting it to recognise a DataSource at design time.

I scoured the help but had no luck until I put this in the code for the control :

Public Property DataSource() As Boolean
Get
Return cboAutocomplete.DataSource
End Get
Set(Value As Boolean)
cboAutocomplete.DataSource = Value
End Set
End Sub

Guess what - like I expected - it complains about DataSource being a Boolean
When I hovered over the DataSource part of the property declaration it says it should be a System.Object

I changed it but when I place the control on a form at design time the DataSource doesn't let me select my dataset like it does if you put a normal combobox.

Any ideas?

kind regards,

Ricky
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
Since the property type is Object, the designer doesn't know what kind of type converter to use, so it uses the standard textBox in the property list. You have to tell it to use the correct TypeConverter, as shown here:

VB.NET:
Imports System.ComponentModel
'...
Private mDataSource As System.Object
<Category("Data"), _
 RefreshProperties(RefreshProperties.Repaint), _
 TypeConverter("System.Windows.Forms.Design.DataSourceConverter," & _
               "System.Design")> _
Public Property DataSource() As System.Object
    Get
        Return mDataSource
    End Get
    Set(ByVal Value As System.Object)
        mDataSource = Value
    End Set
End Property
The 'Category' declaration tells the designer to place the Property in the Data category, the RefreshProperties declaration tells the designer to Repaint the properties when the properties are refreshed, and the important one, the TypeConverter declaration tells the designer to use the System.Windows.Forms.Design.DataSourceConverter TypeConverter located in the System.Design assembly.

Of course the standard comboBox already has a dataSource property. All you need to do is inherit from the comboBox class, then add your autoComplete functionality.
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
Paszt said:
Of course the standard comboBox already has a dataSource property. All you need to do is inherit from the comboBox class, then add your autoComplete functionality.
that's what i did, here's the source code and dll for my autocomplete combobox
 
Top Bottom