- Data Binding
- DataGridView
OrderDataSet
First we will create a simple User Interface,
As you can see in the above figure, the DataGridView control is bind with OrderDetail Table. Note that the Product_ID column is displaying ID which is NOT a friendly approach. Instead Product Name should be displayed here. We can use the DataGridView's ComboBox Column here, in which we will populate all the products.
The main point to be focused here is that, we will be binding the DataGridView control with the same OrderDetail DataTable, in which there is no Product_Name column. But on front-end the Product_ID column will be set to ComboBox Column in which we will populate the Products' Name.
Since we need to populate the ComboBox with Products' Name. Therefore we will add another Typed DataSet and BindingSource to our Form,
We have bind our ProductBindingSource with ProductDataSet which contains Product DataTable. We will fill this table in Form_Load event Handler.
IMPORTANT: This table needs to be filled before we fill the OrderDataSet OR at-least before the OrderDetail DataGridView is displayed
Now we need to setup the Product_ID column. First set the ColumnType of Product_ID column to DataGridViewComboBoxColumn and then set the properties as,- DataPropertyName = Product_ID
- DataSource = ProductBindingSource
- DisplayMember = Product_Name
- ValueMember = Product_ID
4 comments:
Thanks for this! Very helpful article.
No, Its Not Helpful..becuase when we select a datagridviewcolumn item then the remaining columns data should be displayed from database which are related to the specific item in the datagridview
Thank you! Very helpful
Thank you Arsalan, it was very helpful.
Behzad
Post a Comment