Hello,
I add a boolean unbound field to me grid, I'd like to know how to set the default value of this field and how to get notified when the user change the value of the checkBox. In fact I have a checkBox with a undefine value.
Thanks
Hi -
I would avoid keeping references to Cell objects for overhead reasons. To initialize the cell value in InitializeRecord without creating a Cell, do the following:
DataRecord dr = e.Record as DataRecord;
if (dr != null)
dr.SetCellValue(dr.FieldLayout.Fields["Selected"], true);
The SetCellValue method will set the cell value without allocating a Cell object.
Then to know when the cell value has been changed, you could use a regular checkbox (via a custom CellValuePresenter style) and attach a command. You would then bind to the CommandExecute for the command which will get fired when the value of the checkbox is toggled. This post http://forums.infragistics.com/forums/p/5319/24600.aspx#24600 contains a sample project that shows how to create the custom CellValuePresenter style and listen to the command execute when the checkbox is checked.
BTW, the reason you have to use a regular checkbox here nad not a XamCheckEditor is because we are not exposing Command related properties on the XamCheckEditor (which we should probably be doing :-( )
Joe
I found a solution that works pretty well so if that could help anybody else, here is it :
First of all, create an event handler for InitializeRecord into you grid like this : InitializeRecord="MyGrid_InitializeRecord"
After that, we have to create an UnboundField with a checkEditor :
<igDP:UnboundField Name="Selected" Label=" "> <igDP:Field.Settings> <igDP:FieldSettings CellWidth="10" CellMaxWidth="30" EditAsType="{x:Type sys:Boolean}" AllowEdit="True" EditorType="{x:Type igEditors:XamCheckEditor}" /> </igDP:Field.Settings> </igDP:UnboundField>
In the event handler, just get the cell :
private void MyGrid_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e) { DataRecord dr = e.Record as DataRecord; if (dr != null) { Cell cell = dr.Cells["Selected"]; } }
You can so set the defauld value with :
cell.Value = false;
and create an handler for the event PropertyChanged, here is the code :
cell.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(cell_PropertyChanged);
The complete handler look like this :
private void MyGrid_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e) { DataRecord dr = e.Record as DataRecord; if (dr != null) { Cell cell = dr.Cells["Selected"]; cell.Value = false; cell.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(cell_PropertyChanged); } }
You have so an other handler which tells you whe you change the value of the checkBox :
void cell_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { //your code }
I don't know if it's the best may but it works.
I hope that infragistics team will give some comments....
gle