468,511 Members | 1,566 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,511 developers. It's quick & easy.

Trying a custom datagridboolcolumn style

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
Nov 21 '05 #1
2 2109
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
news:eO**************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #2
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.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:O3**************@TK2MSFTNGP09.phx.gbl...
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
news:eO**************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Erald Kulk | last post: by
1 post views Thread by Saso Zagoranski | last post: by
reply views Thread by Alice April via .NET 247 | last post: by
4 posts views Thread by Ubi | last post: by
2 posts views Thread by James Goodman | last post: by
1 post views Thread by B.J. Raiford | last post: by
2 posts views Thread by Jason Huang | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.