[2005] Simple Combobox problem
I just want to add each combobox item into a Toolstrip ComboBox. The next sourcecode will not work:
Code:
Private Sub CopyBoxItems()
Me.ToolStripBox.Items.Clear()
For i As Integer = 0 To FilterBox.Items.Count - 1
Me.ToolStripBox.Items.Add(Me.FilterBox.Items.Item(i))
Next
End Sub
Re: [2005] Simple Combobox problem
Re: [2005] Simple Combobox problem
The box is filled with
System.Data.Datarow etc.
I just can't loop through the Filter Box.
Re: [2005] Simple Combobox problem
You're adding items directly from your FilterBox to the ToolStripBox. If your FilterBox is bound to a DataTable then each of those items is a DataRow, so it's no surprise that that's what you see in the ToolStripBox. If you only want to add the text of each item in the FilterBox to the TooStripBox then that's exactly what you have to do:
vb.net Code:
For Each item As Object In FilterBox.Items
Me.ToolStripBox.Items.Add(FilterBox.GetItemText(item))
Next item
That said, if you have the FilterBox bound to a DataTable then, depending on the circumstances, it may be appropriate to simply bind the ToolStripBox to the same Datatable, e.g.
vb.net Code:
Dim bs As New BindingSource
bs.DataSource = FilterBox.DataSource
With Me.ToolStripBox.ComboBox
.DisplayMember = FilterBox.DisplayMember
.ValueMember = FilterBox.ValueMember
.DataSource = bs
End With
By creating a different BindingSource you enable the two controls to be bound to the data from the same DataTable without having to have the same record selected at the same time.
Re: [2005] Simple Combobox problem [RESOLVED]
Thanx jmcilhinney that workt grate :D