c# - Changing data when itemsource is specified for a datagrid in wpf -
i have datagrid binding observablecollection of custom type. type has boolean property, "iscopying". "binding" done specifying itemsource property of grid observablecollection.
i want change data before bound grid. grid needs read-only view of data. have changed column header using autogeneratingcolumn event:
if (e.column.header.tostring() == "iscopying") { datagridtextcolumn t = new datagridtextcolumn(); t.header = "status"; e.column = t; }
...which works fine. want same thing during binding of individual property cell, of each row. thing work like:
//not real code!!!!!!! private void dgitem_cellbinding(object sender, datagridcellbindingeventargs e) { mycustomtype theitem = e.(mycustomtype)objectgettingbound; if (theitem.iscopying == true) { e.typegettingbound= datagridcelltype.text //or works; e.datatobind = "working..."; }else{ e.typegettingbound = datagridcelltype.text; e.datatobind = "waiting command..."; } }
hopefully above makes sense. can not find event when individual cell binding , how intercept it. sure common i'm new , can't find on addresses particular issue. maybe i'm going wrong way?
does custom type implement inotifypropertychange?
can add public property custom type raises propertychange event , exposes text hat need?
public class mycustomtype: inotifypropertychanged { public event propertychangedeventhandler propertychanged; protected void onpropertychanged(string name) { propertychangedeventhandler handler = propertychanged; if (handler != null) { handler(this, new propertychangedeventargs(name)); } } private bool _iscopying; public bool iscopying { { return _iscopying; } set { _iscopying = value; onpropertychanged("iscopyingtext"); } } public string iscopyingtext { { if(iscopying) return "working..."; else return "waiting command..."; } } }
then bind column iscopyingtext property, , if don't want iscopying column show, set cancel property true in autogeneratingcolumn event (http://msdn.microsoft.com/en-us/library/cc903950(v=vs.95).aspx)
to make grid readonly: http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.isreadonly.aspx
another way use ivalueconverter, here:
Comments
Post a Comment