c# - wpf multiple binding sql and selectedItem -
hi have problem binding. binded data grid result of sql query, dont knew how bind selecteditem. want selecteditem.a
. question how bind multiple things?
this code how binded selcteditem
not working.
xaml:
<datagrid name="grid" itemssource ="{binding}" selecteditem ="{binding path=selecteditem mode=twoway}" autogeneratecolumns="false" verticalalignment="top"> <datagrid.columns > <datagridtextcolumn header="a" binding="{binding path=a, mode=twoway}" visibility="hidden"/> <datagridtextcolumn header="b" binding="{binding path=b, mode=twoway}" /> <datagridtextcolumn header="d" binding="{binding path=c, mode=twoway}" /> </datagrid.columns> <datagrid.itemcontainerstyle> <style targettype="datagridrow"> <eventsetter event="mousedoubleclick" handler="selectrow"/> </style> </datagrid.itemcontainerstyle> </datagrid>
selecteditem
definition:
searchpizzeria _selecteditem; public event system.componentmodel.propertychangedeventhandler propertychanged; public foo selecteditem { { return _selecteditem; } set { throw new exception();//dont rise this._selecteditem = value; this.onpropertychanged("selecteditem"); } } private void onpropertychanged(string propertyname){ var handler = this.propertychanged; if (handler != null) { handler(this, new system.componentmodel.propertychangedeventargs(propertyname)); } }
model:
public class foo { public string { get; set; } public string b { get; set; } public string c { get; set; } }
edit. dont why not binding. must selecteditem or xaml definition.
edit how set data in grid
adapter = new npgsql.npgsqldataadapter(sql, conn); adapter.selectcommand.parameters.addwithvalue("@foo", a_combobox.text); datatable = new datatable(); adapter.fill(datatable); grud.itemssource = datatable.defaultview;
edit first solution cant access hidden data
datarowview row = (datarowview)grid.selecteditems[0]; var x = row["id_user"];
assuming want bind single item, property needs marked public
:
public foo selecteditem { ...
you should check datacontext
, itemssource
grid property bound current datacontext
(which collection assuming items displaying correctly in grid), therefore can't type contains selecteditem
property.
you want datacontext
instance of type contains both collection of items, , selecteditem
property. example view model, if you're using mvvm design pattern.
Comments
Post a Comment