Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have added a dropdown control (with populated data) called cboCustIDs to the first column of the datagridview dgv control.
The dgv is populated with columns such as CustIDs, ValueDate, etc...
I can also add new records inside the dgv.

There is a save button on the form which I want it to save the data in the dgv into the database.

So, I am looping through the rows of the dgv to get the data in the dgv as follows.

For each row, I would like to get the ID value of the item in cboCustIDs which is in the first column of the dgv.

How is this done in the loop please?
Thanks

C#
foreach (DataGridViewRow row in dgv.Rows)
{

//?????
int intcboCustIDsColumn = dgv.Columns[cboCustIDs"].Index;

//????get the Values..
int intCustID = int.Parse(dgv[intcboCustIDsColumn, row.Index].Value.ToString());

}
Posted

1 solution

Hi,

[WinForms] - Please have a look at the following example: Programming DataGridViewComboBoxCell in DataGridView[^]

Kind regards,
 
Share this answer
 
v2
Comments
arkiboys 21-Sep-11 10:48am    
Yes, I am using winforms. Thanks for the link But my question is how to get the id and name values from the combo box in each row of the datagridview while I am looping through the rows of the datagridview? Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900