473,770 Members | 2,519 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making a Custom DataGridColumnS tyle, problems with Paint/Edit fncs.

In VB .Net I made a custom CheckBox column style (for the Datagrid control) that maps to two DataTable columns , one it uses for the Checked status and the other it uses for the Enabled status. I am having a couple problems so far.
1. with the way the Paint method works: When I scroll to the right, the custom column gets Drawn on top of the left-most "Selecting" column (the one where the green arrows are displayed). How can I possibly modify my Paint Method so the column will be underneath the "Selecting" when under-lapping and not display when scrolled far enough to the right. (My custom column is the first column on the left.

2. When I move from CheckBox to Checkbox the Commit method is not fired. And when I click somewhere else on the datagrid I see abnormality in the commit. Changed checkboxes will go back to their default value.

Any help would be greatly appreciated. Here is my code for the class:

Nate

[code]
Imports System
Imports System.Drawing
Imports System.Windows. Forms
Imports System.Data

Public Class DGBoolCol
Inherits DataGridColumnS tyle

Private Const Min_H As Integer = 10
Private Const Pref_H As Integer = 10
Private Const Pref_W As Integer = 50

Protected theCurrencyMana ger As CurrencyManager = Nothing

Private htCheckBoxes As New Hashtable
Private sourceDataTable As New DataTable

Private Allow_Null As Boolean = False

Public Sub New(ByRef dt As DataTable)
sourceDataTable = dt.Copy
End Sub

Protected Overrides Sub Abort(ByVal rowNum As Integer)
Invalidate()
End Sub

Protected Overrides Function Commit(ByVal dataSource As CurrencyManager , ByVal rowNum As Integer) As Boolean
Dim cb As CheckBox = DirectCast(htCh eckBoxes("cbAtR ow" & CStr(rowNum)), CheckBox)
SetColumnValueA tRow(dataSource , rowNum, cb.Checked)

theCurrencyMana ger = Nothing
Invalidate()
Return True
End Function

Protected Overrides Function GetMinimumHeigh t() As Integer
Return Min_H
End Function

Protected Overrides Function GetPreferredHei ght(ByVal g As Graphics, ByVal value As Object) As Integer
Return Pref_H
End Function

Protected Overrides Function GetPreferredSiz e(ByVal g As Graphics, ByVal value As Object) As System.Drawing. Size
Return New Size(Pref_W, Pref_H)
End Function

Protected Overloads Overrides Sub Edit(ByVal source As CurrencyManager , ByVal rowNum As Integer, _
ByVal bounds As Rectangle, ByVal [readOnly] As Boolean)
Edit(source, rowNum, bounds, [readOnly], Nothing)
End Sub

Protected Overloads Overrides Sub Edit(ByVal source As CurrencyManager , ByVal rowNum As Integer, _
ByVal bounds As Rectangle, ByVal [readOnly] As Boolean, _
ByVal instantText As String)
Edit(source, rowNum, bounds, [readOnly], instantText, True)
End Sub

Protected Overloads Overrides Sub Edit(ByVal source As CurrencyManager , ByVal rowNum As Integer, _
ByVal bounds As Rectangle, ByVal [readOnly] As Boolean, _
ByVal instantText As String, ByVal cellIsVisible As Boolean)

Dim cb As CheckBox = DirectCast(htCh eckBoxes("cbAtR ow" & CStr(rowNum)), CheckBox) 'access from HashTbl
cb.Checked = CBool(GetColumn ValueAtRow(sour ce, rowNum))
ColumnStartedEd iting(cb)
theCurrencyMana ger = source

End Sub
Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, _
ByVal source As CurrencyManager , ByVal rowNum As Integer)
Paint(g, bounds, source, rowNum, False)
End Sub

Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, _
ByVal source As CurrencyManager , ByVal rowNum As Integer, _
ByVal alignToRight As Boolean)
Dim drawBrush As SolidBrush = Nothing
drawBrush = New SolidBrush(Data GridTableStyle. BackColor)
g.FillRectangle (drawBrush, bounds)
'drawBrush = New SolidBrush(Data GridTableStyle. ForeColor)

Dim drv As DataRowView = [source].List.Item(rowN um) 'drv.Item(0) The Enabled column of the DT
Dim cb As CheckBox = DirectCast(htCh eckBoxes("cbAtR ow" & CStr(rowNum)), CheckBox)
cb.Checked = GetColumnValueA tRow(source, rowNum)
cb.Enabled = CBool(drv.Item( 0))
cb.Bounds = bounds
cb.Visible = True

AddHandler cb.Leave, AddressOf CBLeave
cb.Focus()
End Sub
Protected Overrides Sub SetDataGridInCo lumn(ByVal value As DataGrid)
If htCheckBoxes.Co unt = 0 Then
If Not (value Is Nothing) Then
For i As Integer = 0 To sourceDataTable .Rows.Count - 1
Dim cb As New CheckBox
cb.Name = "cbAtRow" & CStr(i) 'give the checkbox a name for referencing
cb.Visible = False
cb.Enabled = Allow_Null 'set the enabled value depending on the Enable DB field

htCheckBoxes.Ad d("cbAtRow" & CStr(i), cb) 'add the checkbox to the hashtable
value.Controls. Add(cb) 'add the checkbox to the datagrid controls
Next
End If
End If
End Sub

'Leave Event for calling the commit possibly?
Public Sub CBLeave(ByVal sender As Object, ByVal e As System.EventArg s)

End Sub

Public Property AllowNull() As Boolean
Get
Return (Allow_Null)
End Get
Set(ByVal Value As Boolean)
Allow_Null = Value
'call an UpdateHashTable ()
End Set
End Property

End Class

[\code]
Nov 21 '05 #1
1 3596
Should I try adding the checkboxes to the individual rows or maybe even the
cells the checkboxes will exist in? Does anyone know how to add a checkbox
control to a Cell or Row of a datagrid?
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4271
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found several examples on the web. They all seem to have problems, though that I've been unable to resolve. The most promising example I have found is at:
1
3974
by: The_Rave | last post by:
Hi everyone, I'm trying to add my own template columns to the property builder of ..NET. E.g. a checkbox column, or an image column. But I can't find the sources of the wizard, or a way to add them to the wizard, via add-in? I tried to capture it with a macro, but all I can't get out of it is the raise event of the wizard, nothing that happens during the wizard. "
3
1444
by: Darryn Ross | last post by:
Hi, I am having a few problems with my datagrid, the data in my database isn't coming through right. for example 100.00 in the table is coming through as 100 and 01/01/2004 in the table is coming through as 01/01/2004 10:45 AM??? how do i format my custom table and column styles to reflect the correct data type stored in my tables... my code is as follows.
0
1161
by: Richard | last post by:
Does anyone have a best practices object model for the properties and methods that would typically be involved with the GDI painting, rendering, etc. aspect of this control. Classes surely to be involved will be DataGridTableStyle, DataGridColumnStyle, GridColumnStyles Paint, Brush, Fonts, DataGridTextBoxColumn, DataGridBoolColumn, PointToClient, TableStyles, etc. Basically we want to change row colors, fonts, borders, etc. based on...
2
2338
by: nate axtell | last post by:
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,...
1
1406
by: Richard | last post by:
Does anyone have a best practices object model for the properties and methods that would typically be involved with the GDI painting, rendering, etc. aspect of this control. Classes surely to be involved will be DataGridTableStyle, DataGridColumnStyle, GridColumnStyles Paint, Brush, Fonts, DataGridTextBoxColumn, DataGridBoolColumn, PointToClient, TableStyles, etc. Basically we want to change row colors, fonts, borders, etc. based on the...
9
6174
by: Duncan Barnes-Ceeney | last post by:
I’m having problems with a custom Combo box. The main problem is that I want to modify the look of the combo which includes the size of the button. To do this I have inherited from the standard combo set it as a UserPaint and provided my own paint. This along with the standard Owner Draw for the list items works fine for the DropDownList version, the problems start with the versions with the edit box which are where the problems are. ...
3
1405
by: Richard Ryerson | last post by:
I have a general DataGridComboBoxColumn that I built using the Example in the .NET 2003 Combined Collection help file (that was a data time picker). I am able to assign a data source and display / value members so the ComboBox is data bound and that works, to a point. What generally works is the ComboBox get's populated and the ComboBox shows itself when the appropriate column/row is selected. When the ComboBoxColumn isn't selected it...
2
1324
by: Hamed | last post by:
What does instantText mean in Edit method of DataGridColumnStyle? Regards Hamed
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10058
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.