views:

52

answers:

2

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?

+1  A: 

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.

VinayC
Thanks for the reply. Please can you elaborate a little on the auto postback, and what actually needs to go in the selection change event?
Rezzie
AutoPostBack is property of ComboBox. Setting it true will posts back your page whenever there is change in selection. I wille put pseudo-code for selection change event in the answer it self.
VinayC
A: 

This seems to be already answered. For example here: http://stackoverflow.com/questions/2550473/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.

The answer you linked is for populating ComboBoxes within a DataGridView. I have a ComboBox on my form which is already populated with available orders, I just need the selected one to determine what data is used to populate a separate DataGridView.
Rezzie