Reputation: 4993
I have a form showing the details of a client (various controls), along with their orders (in a DataGridView).
I am trying to add a ComboBox to let the user select one of the client's orders and display the items associated with it in a separate DataGridView.
However, I cannot work out which DataSource/DataBindings I need for either the ComboBox or the items DataGridView - please can anyone give me a few pointers?
Upvotes: 0
Views: 1863
Reputation: 49195
Orders will be the data-source for the ComboBox - OrderId will be the Value field while Order Number or Order Date will be the text field. Items for that order will be data source for the items DataGridView. This grid needs to be bound in the combo-box's selection change event (set auto postback true for the combo box). Hope this helps. Psuedo code for selection change event would be
protected void Orders_SelectedIndexChanged(object sender, EventArgs e)
{
var orderId = int.Parse(Orders.SelectedValue);
// Get items for this order from data store
var items = ...
// Bind with items grid
OrderItems.DataSource = items;
OrderItems.DataBind();
}
Orders is name of combo-box having orders while OrderItems is gridview to display items.
Upvotes: 1
Reputation: 659
This seems to be already answered. For example here: How to get or set data from ComboBox in DataGridView
Or even better, just search for "DataGridView combobox" in StackOverflow and you will find many topics which cover every aspect of that problem.
Upvotes: 0