Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
320
Boolean UnboundFied default value and value changed notification
posted

 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

Parents
  • 320
    posted

     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

Reply Children
No Data