Sunday, 15 May 2011

c# - Get source instance behind the selected DataGrid row -



c# - Get source instance behind the selected DataGrid row -

i have datagrid in xaml , populate setting itemssource this

var mylist = new list<product>(); //product standard class created purpose of populating datagrid mylist.add(new product(){name = "bla", serialnumber = 1234}) mylist.add(new product(){name = "somename", serialnumber = 567}) datagrid.itemssource = mylist;

so each row in datagrid populated values instance of product class.

later in code when user selects row in datagrid , presses key, selected row this

datagrid.selecteditem

but now, cant seem figure out how product instance used create selected row.

so illustration var test = datagrid.selecteditem.instance same doing this var test = new product(){name = "bla", serialnumber = 1234}

the datagrid.selecteditem property should homecoming product instance, if have datagridrow object, can related info item using datagridrow.item property:

product selectedproduct = (product)yourdatagridrow.item;

c# wpf xaml datagrid

No comments:

Post a Comment