I've posted this before and have had some replies (including ClayB), but the functionality is still not all there. Maybe someone in this group has an answer. It seems that most suggestions capture the MouseUp event. I can capture the mouseup event, but I don't know if it caused the checkbox to change. The secret may surround the rowchanging or column changing events (suggested by another post).
If I call DataGrid.EndEdit() this does trigger a columnChanging event, in which I can catch the checkbox change of state. Unfortunately, this seems to take the checkbox out of an editable state, and subsequent click do not change the state of the checkbox. I must move the currentcell before I can edit this checkbox again. Strangely though, pressing the spacebar does change the checkbox value, but alas, the mouse clicks are ignored. If no one has figured out a solution could some one maybe explain some of the relationships between
datagrid.EndEdit/BeginEdit
dataRowView.EndEdit/BeginEdit
dataRow.EndEdit/BeginEdit
dataView.EndEdit/BeginEdit
Thanks alot,
Mitch
CB
Clay Burch
Syncfusion Team
May 3, 2002 08:30 AM
Mitch,
A sample has been added to our FAQ at the link below that adds a BoolValueChanged event to a derived DataGridBoolColumn. The strategy was to handle Edit to save the original state when the cell started being edited. Then in the Paint override check to see if the Paint was being called as a result of the bool value changing. This required checking for the left mouse button being down and the mouse being ove the cell and the grid having focus. Also checked was the state of the keyboard to catch a spacebar being pressed. Getting the keyboard state used the Win32 API GetKeyState.
The strategy seems to work reasonably well in the sample. Maybe it will work for you.
Regards,
Clay
http://www.syncfusion.com/faq/winforms/search/874
TO
Tomas
July 17, 2002 10:30 AM
Mitch,
This solved the problem for me.
// Tomas
' This class raises an event then the CheckBox's checkstate is changed.
Public Class TDDataGridBoolColumn
Inherits System.Windows.Forms.DataGridBoolColumn
Private m_IsInEdit As Boolean = False
Public Event CheckStateChanged(ByVal sender As Object, ByVal e As EventArgs)
Protected Overrides Function Commit(ByVal dataSource As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Boolean
Me.m_IsInEdit = False
Return MyBase.Commit(dataSource, rowNum)
End Function
Protected Overloads Overrides Sub Edit(ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
MyBase.Edit(source, rowNum, bounds, [readOnly], instantText, cellIsVisible)
Me.m_IsInEdit = True
End Sub
Protected Overrides Sub Invalidate()
MyBase.Invalidate()
If Me.m_IsInEdit = True Then
RaiseEvent CheckStateChanged(Me, System.EventArgs.Empty)
End If
End Sub
End Class
TO
Tomas
July 17, 2002 10:31 AM
Mitch,
This solved the problem for me.
// Tomas
' This class raises an event then the CheckBox's checkstate is changed.
Public Class TDDataGridBoolColumn
Inherits System.Windows.Forms.DataGridBoolColumn
Private m_IsInEdit As Boolean = False
Public Event CheckStateChanged(ByVal sender As Object, ByVal e As EventArgs)
Protected Overrides Function Commit(ByVal dataSource As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Boolean
Me.m_IsInEdit = False
Return MyBase.Commit(dataSource, rowNum)
End Function
Protected Overloads Overrides Sub Edit(ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
MyBase.Edit(source, rowNum, bounds, [readOnly], instantText, cellIsVisible)
Me.m_IsInEdit = True
End Sub
Protected Overrides Sub Invalidate()
MyBase.Invalidate()
If Me.m_IsInEdit = True Then
RaiseEvent CheckStateChanged(Me, System.EventArgs.Empty)
End If
End Sub
End Class
AD
Administrator
Syncfusion Team
September 16, 2003 10:34 PM
> Mitch,
>
> A sample has been added to our FAQ at the link below that adds a BoolValueChanged event to a derived DataGridBoolColumn. The strategy was to handle Edit to save the original state when the cell started being edited. Then in the Paint override check to see if the Paint was being called as a result of the bool value changing. This required checking for the left mouse button being down and the mouse being ove the cell and the grid having focus. Also checked was the state of the keyboard to catch a spacebar being pressed. Getting the keyboard state used the Win32 API GetKeyState.
>
> The strategy seems to work reasonably well in the sample. Maybe it will work for you.
>
> Regards,
>
> Clay
>
> http://www.syncfusion.com/faq/winforms/search/874