C# programming - Adding items to a combo box related to data selected in another comb

hanzi_ru

Member
Mar 18, 2008
47
0
0
hi

i have created two combo boxes which contain locations and floors.
After selecting the location from the first combo need to filter the floors allocated to the selected location, to the second combo. i have allocated floors to locations in another table called floor allocate. can somebody pls help

//---Combo Box comLocationName
string Q2 = "SELECT LOCNAME FROM LOCATION ORDER BY LOCNAME ";
CommonAdapter.SelectCommand = new OleDbCommand(Q2, ConnectMe);
CommonAdapter.SelectCommand.ExecuteNonQuery();
DataSet DS2 = new DataSet();
CommonAdapter.Fill(DS2, "D");
DataTable DSTbl2 = DS2.Tables["D"];
comLocationName.DataSource = DS2.Tables[0];
comLocationName.DisplayMember = "LOCNAME";
comLocationName.ValueMember = "LOCNAME";

//---Combo comFloorName
string Q1 = "SELECT FLOORNAME FROM FLOOR ORDER BY FLOORNAME ";
CommonAdapter.SelectCommand = new OleDbCommand(Q1, ConnectMe);
CommonAdapter.SelectCommand.ExecuteNonQuery();
DataSet DS1 = new DataSet();
CommonAdapter.Fill(DS1, "D");
DataTable DSTbl1 = DS1.Tables["D"];
comFloorName.DataSource = DS1.Tables[0];
comFloorName.DisplayMember = "FLOORNAME";
comFloorName.ValueMember = "FLOORNAME";
 

amilabanuka

Well-known member
  • Sep 30, 2006
    7,291
    878
    113
    Thama math hoyanooo....
    is there any raletion between floor and location...
    ie. some floors are not available for some locations?.
    if not no need to have second list to be allocated after the first selection.
    you can just bind them.