|
-
Aug 17th, 2007, 09:15 AM
#1
Thread Starter
Lively Member
[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
Last edited by fatihpk; Aug 17th, 2007 at 09:33 AM.
-
Aug 17th, 2007, 09:17 AM
#2
Re: [2005] Simple Combobox problem
-
Aug 17th, 2007, 09:34 AM
#3
Thread Starter
Lively Member
Re: [2005] Simple Combobox problem
The box is filled with
System.Data.Datarow etc.
I just can't loop through the Filter Box.
-
Aug 17th, 2007, 10:40 PM
#4
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.
-
Aug 19th, 2007, 02:50 AM
#5
Thread Starter
Lively Member
Re: [2005] Simple Combobox problem [RESOLVED]
Thanx jmcilhinney that workt grate
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|