472,951 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 software developers and data experts.

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 2261
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Erald Kulk | last post by:
I have a problem with a datagridboolcolumn that drives me almost crazy. I have a sql server table with several columns of which one is a column called ok which is a bit with default value 0. In...
1
by: Saso Zagoranski | last post by:
Hi! I have extended the default windows.forms datagrid... I added a few options if the data is bound programmaticly... The main part of the function (the for loop) loops through all the columns...
0
by: Alice April via .NET 247 | last post by:
(Type your message here) I use bool column in my datagrid. but I get all grayed checkswhen I first load it. I know it is about the DBNULL state, but ihave set Col.AllowNull = False. my column data...
2
by: PeterZ | last post by:
Hi, In the past I've successfully databound a conventional Winforms checkbox to a number column in an Oracle table, where 1 represents true and 0 represents false. The checkbox would be ticked...
4
by: Ubi | last post by:
Hi, my code is: myDataTBL.Columns.Add("checked",System.Type.GetType("System.Boolean")); DataGridBoolColumn cs1 = new DataGridBoolColumn(); cs1.NullValue=false; cs1.TrueValue=true;...
2
by: James Goodman | last post by:
I have a number of bool columns within a datagrid, but they dont work as expected. The underlying table is Access 2000. The datatype for the underlying fields is Yes/No. I am attempting to...
1
by: B.J. Raiford | last post by:
I have a DataGrid on a form in my application that is bound to an xml file and I have set the table style to contain a few columns with one editable one, a DataGridBoolColumn. I set...
1
by: Will | last post by:
Hello, I wrote a custom object that Inherits from CollectionBase. This would, my object fits in a datagrid. However, my object (_obj) contains data and references I do NOT want the datagrid...
2
by: Jason Huang | last post by:
Hi, In VS2003, C# Windows form project, on my DataGrid1. The first column's style in my DataGrid1 is DataGridBoolColumn. When I first click that checkbox, the checkbox doesn't turn to checked,...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.