0

I have following code in an extended DataGrid to check or uncheck the CheckBoxColumn:

            if (this.Columns[c] is DataGridCheckBoxColumn)
            {
                CheckBox cb = this.GetCellCtrl<CheckBox>(this.Columns[fromCol], topRow);
                for (int r = fromRow + 1; r <= toRow; r++)
                {
                    CheckBox tt = this.GetCellCtrl<CheckBox>(this.Columns[fromCol], this.GetRow(r));
                    if (tt != null)
                        tt.IsChecked = cb.IsChecked;
                }
            }

The problem is that the checkboxes are checked (or unchecked), but the underlying data are not updated. If I mouse-clicking the checkbox, it works. So, what's the difference between my code and mouse-clicking? How to solve my problem?

1 Answer 1

1

Setting a value locally will remove the binding that couples your CheckBox to your data. Is there any reason why you are updating the state of your data via the UI? Why not use your same loop logic on the data?

If you really must do it this way, you should look into UI Automation:

http://msdn.microsoft.com/en-us/library/ms747327.aspx

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for your response. I'm not looking for UI Automation. I'm just trying to create a generic function to make the selected cells checkable independent of underlying data source - if it's a DataGridCheckBoxColum, the binding data must be bool type. I practically try to simulate a mouse click of the CheckBoxes. From my testing, the binding doesn't seem to be decoupled, because I could still click it and the underlying data reflects the change.
You said "Setting a value locally will remove the binding" - How does this work? How can I restablish the binding?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.