c# - Dynamically hide a row in a DataGrid -
i want hide 1 row of datagrid
when user selects row.
how can that?
private void datagridcommands_selectionchanged(object sender, selectionchangedeventargs e) { (int = 0; < datagriddata.items.count; i++) { if ((datagriddata.items[i] datafortable).msgtype == _qf.elementat(datagridcommands.selectedindex).mcode) { //need hide 1 row datagriddata } } }
i not know logic want use hidding row datagrid, show simple sample.
the point need retrive container of row , hide it. let's see how. xaml:
<stackpanel> <datagrid autogeneratecolumns="true" canuseraddrows="false" selectionchanged="datagrid_selectionchanged" name="datagrid" /> </stackpanel>
and code-behind:
public partial class window3 : window { private observablecollection<person> people = new observablecollection<person>(); public window3() { initializecomponent(); people.add(new person() { name = "paul", surname = "green" }); people.add(new person() { name = "mike", surname = "gray" }); people.add(new person() { name = "john", surname = "black" }); datagrid.itemssource = people; } private void datagrid_selectionchanged(object sender, selectionchangedeventargs e) { datagridrow datagridrow; foreach (person p in e.addeditems) { if (p.name == "mike") { datagridrow = datagrid.itemcontainergenerator.containerfromitem(people[2]) datagridrow; datagridrow.visibility = system.windows.visibility.collapsed; return; } } datagridrow = datagrid.itemcontainergenerator.containerfromitem(people[2]) datagridrow; datagridrow.visibility = system.windows.visibility.visible; } }
my logic want hide last person object in collection if user select person named "mike". retrieve container (a datagridrow in case) correspond row want hide/show. set visibility right value.
i hope sample can give hint issue.
Comments
Post a Comment