c# - Change datagrid selected item using two comboboxes -
i have datagrid containing information users
username userid userhobby
and have combobox linked each of columns above. if user select of boxes individually brings selected datagrid row first occurance of matching row. if instance user selects value "bryan" username , hobby "golf" want selected cell move row both values present.
at moment selectedindexchanged code second combobox follows :
datagrid.selectedrows = datagrid.selectedrows.where( x =>x.row.field<string>(datagrid.text) .contains(hobbycombobox.text));
however not working , have similar approach or solution
based on feedback answers code looks
var query = datagrid.selectedrows.cast<datagridviewrow>() .where(x => x.row.field<string> (datagrid.text).contains(combobox10.text)); datagrid.datasource = query.tolist(); datagrid.refresh()
however throwing error on x.row
system.windows.forms.datagridviewrow' not contain definition 'row' , no extension method 'row' accepting first argument of type 'system.windows.forms.datagridviewrow'
datagrid.selectedrows read only. need rebind datasource.
var query = datagrid.selectedrows.cast<datagridviewrow>() .where(x =>x.row.field<string>(datagrid.text).contains(hobbycombobox.text)); datagrid.datasource=query; datagrid.refresh();
Comments
Post a Comment