本文介绍了除非焦点更改,否则未注册DevExpress XtraGrid复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Windows窗体上有一个数据绑定的XtraGrid.列之一是复选框.问题如下:当用户选中复选框并单击确定"按钮时,该复选框在可见的情况下不会被网格视为已选中.当我这样做时(遍历行):

We have a databound XtraGrid on our Windows form. One of the columns is a check box. The problem is as follows: when users check the checkbox and click OK button, the checkbox, while visibly checked, is not considered checked by the grid. When I do this (while looping through rows):

isAllowed = Convert.ToBoolean(viewMain.GetRowCellValue(nRowCtr, "IsAllowed"))

我回来了False.但是,如果用户选中了该框,然后单击了表单上其他位置或此网格中的另一行,从而使焦点从选中的复选框中移开,则上面的相同代码将返回True.

I get back False. BUT, if the user checks the box, and then clicks somewhere else on the form or on another row in this grid, thus taking away focus from the checked checkbox, the same code above will return True.

对于解决此问题的任何见解,将不胜感激.

Any insight on how to fix this behavior would be greatly appreciated.

找到解决方法:使用默认设置,当用户单击一个单元格进行编辑时,该单元格进入编辑模式,加载编辑器控件(在这种情况下,我有一个CheckEdit存储库控件)并更改控件的值(在这种情况下,为选中状态).如果单击另一行或其他控件,则该单元将退出编辑模式,将更改提交到数据项.但是,如果我单击一个按钮,则我的更改将丢失.解决方法是使用CheckEdit的CheckedChanged事件关闭编辑器:

Workaround found:With default settings, when users click on a cell to edit it, the cell goes into edit mode, loads the editor control (in this case I have a CheckEdit repository control) and changes control's value (in this case checked state). If I click on another row, or another control, the cell then gets out of edit mode, committing the change to data item. But if I click on a button, then my change is lost. The workaround is to use the CheckEdit's CheckedChanged event to close editor:

Private Sub edCheck_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles edCheck.CheckedChanged
        gridYears.FocusedView.CloseEditor()
End Sub

推荐答案

实际上,有一种更清洁的方法(适用于所有RepositoryItems),有关详细信息,请参见 DevExpress网站.想法是从存储库项目的EditValueChanged事件处理程序中调用GridView.PostEditor方法,以立即将编辑后的值保存到网格的单元格和基础列中.

There's actually a cleaner way of doing this (it works for all RepositoryItems), detailed on the DevExpress site. The idea is to call the GridView.PostEditor method from a repository item's EditValueChanged event handler to immediately save the edited value to the grid's cell and the underlying column.

这篇关于除非焦点更改,否则未注册DevExpress XtraGrid复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 21:46