|
-
Jan 24th, 2011, 03:41 AM
#1
Thread Starter
Lively Member
[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...
-
Jan 24th, 2011, 05:18 AM
#2
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
-
Jan 24th, 2011, 05:40 AM
#3
Thread Starter
Lively Member
Re: Populating the information into a ComboBox... ???
 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!
-
Jan 24th, 2011, 06:13 AM
#4
Thread Starter
Lively Member
Re: Populating the information into a ComboBox... ???
 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
-
Jan 24th, 2011, 08:23 AM
#5
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.
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
|