I am new this forum and i am one of person interest i programming language.

I am trying one small application to create. But i don't have proper guidance. I request help here.

Just a asset management process.
There are 2 tables
Category -> Catid, Catname
SubCategory -> Catid, Subcat, preasset

Those 2 above tables have data to fill in the combo box but, based on first combo box selection, data to be filter in the second combo box(only specific data which is corresponding to category) and preasset value to be posted in one text window.

Those filter should be work based on catid field of category table.

This request seems to be old but, i did not get proper link in web.

Any idea to accomplish this.



5 Years
Discussion Span
Last Post by spider2vb

First fill Cat combo with data member and value member.
Get the data for secod combo in dataset. in selected index changed event, get the key value of selected item using view sort the items and fill the secon combo.


Yep.. do it this way:

Public Sub New()
	'in  constructor or in load event (before showing actually):
	comboBox1.DataSource = New BindingSource(table1, Nothing)
	comboBox1.DisplayMember = "Catname"
	comboBox1.ValueMember = "Carid"
	'subscribe to an event:
	comboBox1.SelectedIndexChanged += New EventHandler(AddressOf comboBox1_SelectedindexChanged)
End Sub

Private Sub comboBox1_SelectedindexChanged(sender As Object, e As EventArgs)
	'get value of comboBox1:
	Dim drv As DataRowView = DirectCast(comboBox1.SelectedItem, DataRowView)
	Dim value As Integer = Convert.ToInt32(drv("Catid"))

	'now get new data from datatable2 (or from dataSet):
	Dim rows As DataRow() = table2.[Select]("Catid = '" & value & "'")
	Dim tableSelected As DataTable = table2.Clone()
	For Each row As DataRow In rows

	'bind new table to comboBox2:
	combobox2.DataSource = Nothing
	comboBox2.DataSource = New BindingSource(tableSelected, Nothing)
	comboBox2.DisplayMember = "preasset"
	comboBox2.ValueMember = "Subcat"
	'or what ever use for the value (if needed, but I guess you wont need it at all).
End Sub

Note: table1 represents your dataTable1, and table2 is DataTable2 (like you said).


comboBox1.SelectedIndexChanged += New EventHandler(AddressOf comboBox1_SelectedindexChanged)

somthing wrong in this line

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.