tieing combo boxes to getchildren of a row

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

If you have two combo boxes, and when one changes you want the other to
update its available items, is it possible to bind the second combo box
somehow using the getchildren method of the selected row from the first
combo box? how would you guys go about doing something like this with
ado.net? thanks
 
Thanks for Greg's quick response!

Hi Brian,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need the second combobox on the
form displays items according to child rows of the first combobox. If there
is any misunderstanding, please feel free to let me know.

I agree with Greg's suggestion to use GetChildRows on a DataRelation
object. It's better to use a typed DataSet for convenience. We can handle
the SelectedValueChanged event of the first combobox to change items in the
second one. Here I have written a code snippet for your reference. HTH.

private void Form1_Load(object sender, System.EventArgs e)
{
SqlDataAdapter sda1 = new SqlDataAdapter("SELECT * FROM Customers",
this.sqlConnection1);
SqlDataAdapter sda2 = new SqlDataAdapter("SELECT * FROM Orders",
this.sqlConnection1);
sda1.Fill(dataset11.Customers);
sda2.Fill(dataset11.Orders);

this.comboBox1.DisplayMember = "CompanyName";
this.comboBox1.ValueMember = "CustomerID";
this.comboBox1.DataSource = dataset11.Customers;

this.comboBox2.DisplayMember = "OrderDate";
this.comboBox2.ValueMember = "OrderID";
}

private void comboBox1_SelectedValueChanged(object sender,
System.EventArgs e)
{
if(this.comboBox1.SelectedValue != null)
{
this.comboBox2.DataSource =
dataset11.Customers.FindByCustomerID(this.comboBox1.SelectedValue.ToString()
).GetChildRows(dataset11.Relations["CustomersOrders"]);
}
}

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi Brian,

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi!

I need this kind on thing also, but I don't understand what is
"FindByCustomerID" in the following C# sample below? I'm using VB.NET 2003,
maybe this same sample code as VB code would help me better to figure out
it.
 
Back
Top