I want to fill a combo box depending on another combo box.I tried to find it for 2 days.
I have a database with 3 tables.
ID, BrandName
ID, SerieName, BrandID
ID, ProfileNam, SerieID
My Form is like this.
First combo box fill with Brandname
and its working well with the code below.
private void MarkaYukle()
{
string dbBaglantiYolu = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\Personal Files\\Otomasyon\\VB\\SmallCNC_V01.00\\database\\database01.mdb";
try
{
using (OleDbConnection baglanti=new OleDbConnection(dbBaglantiYolu))
{
baglanti.Open();
string dataYolu = "SELECT * FROM Markalar";
OleDbDataAdapter adaptor = new OleDbDataAdapter(dataYolu, baglanti);
DataSet ds = new DataSet();
adaptor.Fill(ds);
comboMarkaSec.DataSource = ds.Tables[0];
comboMarkaSec.DisplayMember = "MarkaAdi";
comboMarkaSec.ValueMember = "ID";
}
}
catch(Exception ex)
{
}
}
What I want, when I select brand, I want combobox2
to be filled with series name
. But only if BrandID
equal to selected combobox1
brandID.
For example, car brand AUDI, VOLVO for first combobox, and second show only model of car brand, A4/A3 and V40/V90 etc.
I can use combobox2.fill
command, and also its working. But I need ID of SeriesName
also becasue, I will use it at listbox
to show. For example motor spec. Like 1.6lt DSG / 2.2lt Manual etc.
Hope I can explain it with my bad English. Thanks.