Combo loads datasource but not items

avalon

Member
Joined
Feb 6, 2007
Messages
7
Programming Experience
1-3
Hi all,

.Net: v1.1
Software: Visual Studio 2003

I have a usercontrol that dynamically creates a combobox control and alligns it on the usercontrol. Now I want to add a property to the usercontrol to assign a default value to this combobox.

I already have properties for datasource, displaymember and valuemember and the combobox loads it's data just fine.

So what I do to get the defaultvalue to work is this:
VB.NET:
Expand Collapse Copy
    Public Property ComboSelectedValue() As Object
        Get
            If Not cboCombo Is Nothing Then Return cboCombo.SelectedValue
        End Get
        Set(ByVal Value As Object)
            If Not cboCombo Is Nothing Then
                cboCombo.Update()
                cboCombo.Refresh()
                cboCombo.SelectedValue = Value
                mstrDefaultComboValue = CString(Value)
            End If
        End Set
    End Property
This usercontrol variable mstrDefaultComboValue is also used for this piece of code in the UserControl_Load event:
VB.NET:
Expand Collapse Copy
        If Not cboCombo Is Nothing Then
            With cboCombo
                .Top = btnAdd.Top
                .Left = 8
                .Width = Me.grpMain.Width - btnAdd.Width - 16
                .DropDownWidth = Me.grpMain.Width - btnAdd.Width - 16
                .DropDownStyle = ComboBoxStyle.DropDownList
                .SelectedValue = mstrDefaultComboValue
            End With
        End If

Now I don't know why but for some reason this combo doesn't load it's Items collection even though the datasource is loaded!

So my question to you is, on which event does the combobox load the Items collection from what is in the DataSource of the combo?


Thanks a lot!
 
Anyone please?

To put the question more simple:
Internally in the system.windows.forms.combobox control, when are the items loaded into the combobox from the datasource?
 
Back
Top