Deaking with ComboBoxes and databases

  • Thread starter Thread starter juventusaurabh
  • Start date Start date
J

juventusaurabh

Hi,
I have a couple of combo boxes and the data inthe combo boxes is
from the SQL database. I have created datasets to reflect that data in
one of the combo box.
But, what I want is that, when I select certain data from one combo
box, the data in other comboBox should automatically reflect the
related data from the first combo box.
For example, If I select a state IL from comboBox1 (from dataset from
sql database "state" column), then the values in comboBox2 should
automatically reflect only cities from IL (from the sql database table
"city" column).

Can anyone assist?? I would appreciate if anyone can even give me
references for related examples.


Thanks,
 
First combo box

lstSelectItem.DataSource = null;
lstSelectItem.DataSource = dtSelect;
lstSelectItem.DisplayMember = "Name";
lstSelectItem.ValueMember = "ID";


In selectedIndexchange of the above.. u could write the below

private void lstSelectItem_SelectedValueChanged(object sender, EventArgs
e)
{
lstLinked.DataSource = null;
DataRowView dtView = ((DataRowView)lstSelectItem.SelectedItem);
int intLocalUnqiueID = int.Parse(dtView["ID"].ToString());
dvLinked.RowFilter = "ID = " + intLocalUnqiueID;
lstLinked.DataSource = dvLinkedRows;
lstLinked.DisplayMember = "Name";
lstLinked.ValueMember = "ID";
}

HTH
VJ
 
Hi VJ,
Thanks, But Iam not able to figure what is dvLinked.RowFilter
in ur snippet. Can you please explain what is dvLinked?
 
Sorry my bad.. it has to be dvLinkedRows. essentially u filter dvLinkedRows
and then set the filtered thing to the source.

VJ

vj said:
First combo box

lstSelectItem.DataSource = null;
lstSelectItem.DataSource = dtSelect;
lstSelectItem.DisplayMember = "Name";
lstSelectItem.ValueMember = "ID";


In selectedIndexchange of the above.. u could write the below

private void lstSelectItem_SelectedValueChanged(object sender, EventArgs
e)
{
lstLinked.DataSource = null;
DataRowView dtView = ((DataRowView)lstSelectItem.SelectedItem);
int intLocalUnqiueID = int.Parse(dtView["ID"].ToString());
dvLinked.RowFilter = "ID = " + intLocalUnqiueID;
lstLinked.DataSource = dvLinkedRows;
lstLinked.DisplayMember = "Name";
lstLinked.ValueMember = "ID";
}

HTH
VJ
juventusaurabh said:
Hi,
I have a couple of combo boxes and the data inthe combo boxes is
from the SQL database. I have created datasets to reflect that data in
one of the combo box.
But, what I want is that, when I select certain data from one combo
box, the data in other comboBox should automatically reflect the
related data from the first combo box.
For example, If I select a state IL from comboBox1 (from dataset from
sql database "state" column), then the values in comboBox2 should
automatically reflect only cities from IL (from the sql database table
"city" column).

Can anyone assist?? I would appreciate if anyone can even give me
references for related examples.


Thanks,
 
Back
Top