c# - DataGrid: How to manipulate selected item -
this must simple searching leads binding-based solutions, not case.
i have datagrid in there datagridcomboboxcolumn. column's itemssource property bound string array. use loop in startup set selecteditem of column each row of datagrid through code:
for (int = 0; < dgresults.items.count; i++) { var x = dgresults.getcell(i, 0).content system.windows.controls.combobox; x.selecteditem = "one of items of array"; } getcell() extension method grabbed here.
now problem when click on particular cell of column, dropdown appears in cell , correctly populated array items, dropdown's current text empty, i.e. doesn't automatically select corresponding item dropdown. missing?
edit
here relevant portion of datagrid:
<datagrid x:name="dgresults" autogeneratecolumns="false" > <datagrid.columns> <datagridcomboboxcolumn itemssource="{staticresource remindervalues }" /> </datagrid.columns> </datagrid> as can see, particular column not bound underlying datacolumn or something, although whole datagrid bound datatable. also, know sure not spelling issue.
finally figured out after taking sleep. if you've got unbound datagridcomboboxcolumn in grid (i.e. column doesn't bind column in underlying data source) , itemssource property bound array or something, must add following datagrid declaration:
selecteditembinding="{binding /}" the slash character (/) above represents current item itself, want our selecteditem be.
now datagrid displays values correctly , once cell gets focus, combobox appears correct value selected.
Comments
Post a Comment