开发者

How to bind data in WPF DataGrid in code?

开发者 https://www.devze.com 2023-03-15 13:20 出处:网络
I have following code in an extended DataGrid to check or uncheck the CheckBoxColumn: if (this.Columns[c] is DataGridCheckBoxColumn)

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消