Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
basically i have datagridview which columns are:
columncombobox, columntextbox, columntextbox, columntextbox, columncombobox,

1. i need on button1 clicked to get the item text from the right combobox.
2. i need to make event handlers on both combobox changed.

basically i need to execute code on the first combobox item changed and different code to be executed on the right combobox item change
picture

how to do this, since its different than the classic win forms combobox, there it has a prepared event on item changed.

thanks in advance, i didnt successed in finding the solution online so i asked here, if u need more info, ask and i will reply.
Posted

1 solution

for (int i = 0; i <= dgList.Rows.Count - 1; i++) 
            { 
                DataGridViewComboBoxCell cell = dgList.Rows[i].Cells[0] as DataGridViewComboBoxCell; 
                string strVal = cell.Value.ToString();
                string strtext = cell.OwningColumn.HeaderText();
            }

//Cell.OwningColumn exposes the column that owns the selected cell.
 

//This code gives the heading of the owning column.

OR

//If I say you want the formatted value (text) and the selected value (value) then //in that case try this :

 for (int i = 0; i <= dgList.Rows.Count - 1; i++) 
            { 
                DataGridViewComboBoxCell cell = dgList.Rows[i].Cells[0] as DataGridViewComboBoxCell; 
                string strVal = cell.Value.ToString();
                string strtext = cell.FormattedValue.ToString();
            }
 
Share this answer
 
Comments
SrgjanX 7-Feb-15 6:36am    
thanks for the code man, i find a way to executed different code which checking which combobox was used, and this helped me to read the text from the combobox, i forget to create a object of datagridviewcomboboxcell, i was creating object of datagridviewcell.
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