Check the checkbox only when clicking on the check and not when clicking on the header

May 1, 2011 at 12:25 PM


Just implemented this. May be somebody will be interested. At least the author of corresponding TODO in sources will do.

Where mframe - Windows Form, ListView1 - grid itself.

Private Class CheckBoxColumn
        Inherits SourceGrid.Cells.Controllers.CheckBox
        ' Methods
        Public Sub New(ByVal frame As frmMain)
            Me.mframe = frame
        End Sub      
        Public Overrides Sub OnClick(ByVal sender As SourceGrid.CellContext, ByVal e As System.EventArgs)
            Dim v1 As Cells.Views.CheckBox = sender.Cell.View
            Dim e1 As MouseEventArgs = e
            Dim locationOnForm As Point = mframe.ListView1.FindForm().PointToClient(

            Dim measure As DevAge.Drawing.MeasureHelper = New DevAge.Drawing.MeasureHelper(mframe.ListView1)
            Dim cellArea, checkboxArea, elementCheckboxArea As RectangleF
            Dim cellTop, cellLeft, cellHeight, cellWidth As Integer
            cellTop = mframe.ListView1.Rows.GetTop(sender.Position.Row)
            cellLeft = mframe.ListView1.Columns.GetLeft(sender.Position.Column)
            cellHeight = mframe.ListView1.Rows.GetHeight(sender.Position.Column)
            cellWidth = mframe.ListView1.Columns.GetWidth(sender.Position.Column)
            cellArea = New RectangleF(cellLeft, cellTop, cellWidth, cellHeight)
            checkboxArea = v1.GetDrawingArea(measure, cellArea)
            elementCheckboxArea = v1.ElementCheckBox.GetDrawingArea(measure, checkboxArea)

            Dim elms As DevAge.Drawing.VisualElements.VisualElementList =
                v1.ElementCheckBox.GetElementsAtPoint(measure, elementCheckboxArea, New PointF(e1.X, e1.Y))
            If (elms.Count = 1 AndAlso elms(0) Is v1.ElementCheckBox) Then
                MyBase.OnClick(sender, e)
            End If
        End Sub  
        ' Fields
        Private mframe As frmMain
    End Class