[RESOLVED] Populating the information into a ComboBox... ???
I need to populate some information into several ComboBoxes.
The infromation should be read from the table in my database. Is it possible to read the information and populate it onto a combobox without using data binding?
I tried to populate several ComboBoxes, but if I use databinding, the ComboBoxes all show the same value. Also, if I select a certain value, it also selects that row in the table, which I do not wish to do...
Re: Populating the information into a ComboBox... ???
Yes it is possible to do without data-binding but you shouldn't. You should use data-binding but just do it correctly. If you want to bind two ComboBoxes to two different columns in the same DataTable and have them select independently then you do it like this:
vb.net Code:
Dim view1 As New DataView(myDataTable)
Dim view2 As New DataView(myDataTable)
With ComboBox1
.DisplayMember = "Column1"
.ValueMember = "ID"
.DataSource = view1
End With
With ComboBox2
.DisplayMember = "Column2"
.ValueMember = "ID"
.DataSource = view2
End With
Re: Populating the information into a ComboBox... ???
Quote:
Originally Posted by
jmcilhinney
Yes it is possible to do without data-binding but you shouldn't. You should use data-binding but just do it correctly. If you want to bind two ComboBoxes to two different columns in the same DataTable and have them select independently then you do it like this:
vb.net Code:
Dim view1 As New DataView(myDataTable)
Dim view2 As New DataView(myDataTable)
With ComboBox1
.DisplayMember = "Column1"
.ValueMember = "ID"
.DataSource = view1
End With
With ComboBox2
.DisplayMember = "Column2"
.ValueMember = "ID"
.DataSource = view2
End With
:)
Thank you!
Re: Populating the information into a ComboBox... ???
Quote:
Originally Posted by
jmcilhinney
Yes it is possible to do without data-binding but you shouldn't. You should use data-binding but just do it correctly. If you want to bind two ComboBoxes to two different columns in the same DataTable and have them select independently then you do it like this:
Is it possible to add and remove values from the ComboBoxes at this point? I would like the ComboBoxes not to repeat already used values.
I didn't get it to work with the code below:
vb.net Code:
Dim view1 As New DataView(myDataTable)
Dim view2 As New DataView(myDataTable)
With ComboBox1
.DisplayMember = "Column1"
.ValueMember = "ID"
.DataSource = view1
.Items.Remove(ComboBox2.Text)
.Items.Remove(ComboBox3.Text)
.Items.Remove(ComboBox4.Text)
.Items.Remove(ComboBox5.Text)
End With
With ComboBox2
.DisplayMember = "Column2"
.ValueMember = "ID"
.DataSource = view2
.Items.Remove(ComboBox1.Text)
.Items.Remove(ComboBox3.Text)
.Items.Remove(ComboBox4.Text)
.Items.Remove(ComboBox5.Text)
End With
Re: Populating the information into a ComboBox... ???
It's possible but not like that. I would suggest binding each DataView via a BindingSource. You can then handle the CurrentChanged event of each BindingSource and set the Filter property of each other BindingSource to filter out the records that have been selected.