c# - Getting the index of a ComboBox in in a DataGridView -
i have system.windows.forms.datagridview
in 1 column has comboboxes. when changes in combobox, need know new item is, , row index of combobox in event took place. latter giving me trouble. have following:
class myform : form { private system.windows.forms.datagridview m_gridview; private system.windows.forms.datagridviewcomboboxcolumn m_comboboxcolumn; public myform () { /* ... lots of initialisation stuf...*/ this.m_gridview.columns.addrange(new system.windows.forms.datagridviewcolumn[] { this.m_comboboxcolumn}); } private void m_gridview_editingcontrolshowing(object sender, datagridvieweditingcontrolshowingeventargs e) { combobox combobox = e.control combobox; if (combobox != null) { combobox.selectedindexchanged -= new eventhandler(m_comboboxcolumn_selectedindexchanged); combobox.selectedindexchanged += new eventhandler(m_comboboxcolumn_selectedindexchanged); } } private void m_comboboxcolumn_selectedindexchanged(object sender, eventargs e) { combobox combobox = (combobox) sender; string item = combobox.text; if (item != null) { system.diagnostics.debug.writeline(item); // new item text // need row index of combobox in 'm_gridview' (or 'm_comboboxcolumn') } } }
how can find row index of combobox in datagridviewcomboboxcolumn
in last method?
you should cast datagridviewcomboboxeditingcontrol
, access editingcontrolrowindex
row index this:
var combobox = (datagridviewcomboboxeditingcontrol)sender; int rowindex = combobox.editingcontrolrowindex;
Comments
Post a Comment