We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

CheckBox change event in DataGrid bool column

Thread ID:

Created:

Updated:

Platform:

Replies:

216 May 2,2002 09:01 PM UTC Sep 17,2003 03:34 AM UTC Windows Forms 4
loading
Tags: FAQ
mitch
Asked On May 2, 2002 09:01 PM UTC

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

Clay Burch [Syncfusion]
Replied On May 3, 2002 01:30 PM UTC

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

Tomas
Replied On July 17, 2002 03:30 PM UTC

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

Tomas
Replied On July 17, 2002 03:31 PM UTC

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

Administrator [Syncfusion]
Replied On September 17, 2003 03:34 AM UTC

> 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;