Trying a custom datagridboolcolumn style

N

nate axtell

I'm trying to create a custom DataGridBoolColumn. I inherit
DataGridColumnStyle and create a public CheckBox variable. This columnType
will be mapped to a dataTable boolean column. What are the basics of the
Draw and Edit methods that I need to implement in order to see the checkbox
in the cell?
I have tried the following, but it hasn't worked. (CB is the public
checkbox):

Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As
Rectangle, ByVal [source] As CurrencyManager, ByVal rowNum As Integer, ByVal
backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)
Dim value As Boolean
If IsDBNull(GetColumnValueAtRow([source], rowNum)) Then
value = False
Else
value = CBool(GetColumnValueAtRow([source], rowNum))
End If

CB.Visible = True
CB.Location = New Point(bounds.Left, bounds.Top)
CB.Checked = value
CB.Show()
CB.Focus()
CB.BringToFront()

End Sub

Protected Overloads Overrides Sub Edit(...)
CB.Visible = True
CB.Location = New Point(bounds.Left, bounds.Top)
CB.Checked = value
CB.Show()
CB.Focus()
End Sub
 
K

Ken Tucker [MVP]

Hi,

I wouldnt try to paint a bool column. I would set the column value
and let the column style handle the painting.


Public Class NoNullBoolColumn

Inherits DataGridBoolColumn

Protected Overrides Function GetColumnValueAtRow(ByVal lm As
System.Windows.Forms.CurrencyManager, ByVal row As Integer) As Object

Dim objNull As Object = Convert.DBNull

If objNull.Equals(MyBase.GetColumnValueAtRow(lm, row)) Then

Return False

Else

Return MyBase.GetColumnValueAtRow(lm, row)

End If

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)

If FalseValue.Equals(GetColumnValueAtRow(source, rowNum)) Then

setcolumnvalueatrow(source, rowNum, TrueValue)

Else

setcolumnvalueatrow(source, rowNum, FalseValue)

End If

End Sub



End Class



Ken

-------------------------

"nate axtell" <naxtell at progeny dot net> wrote in message
I'm trying to create a custom DataGridBoolColumn. I inherit
DataGridColumnStyle and create a public CheckBox variable. This columnType
will be mapped to a dataTable boolean column. What are the basics of the
Draw and Edit methods that I need to implement in order to see the checkbox
in the cell?
I have tried the following, but it hasn't worked. (CB is the public
checkbox):

Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As
Rectangle, ByVal [source] As CurrencyManager, ByVal rowNum As Integer, ByVal
backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)
Dim value As Boolean
If IsDBNull(GetColumnValueAtRow([source], rowNum)) Then
value = False
Else
value = CBool(GetColumnValueAtRow([source], rowNum))
End If

CB.Visible = True
CB.Location = New Point(bounds.Left, bounds.Top)
CB.Checked = value
CB.Show()
CB.Focus()
CB.BringToFront()

End Sub

Protected Overloads Overrides Sub Edit(...)
CB.Visible = True
CB.Location = New Point(bounds.Left, bounds.Top)
CB.Checked = value
CB.Show()
CB.Focus()
End Sub
 
N

nate axtell

I would inherit the boolcolumn but I am trying to do a dual mapping. The
normal mapping will determine the value displayed and the second mapping
will determine the ReadOnly value of the row.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top