Hi,
Like you said you have to make a class that inhertits from a
datagrid column style. Add a procedure that shadows beginupdate and
endupdate for this to work. Here is an example. Hope this helps
Private Sub BeginEndUpdate()
Dim dgc As DataGridColumnStyle
Dim dgCols As GridColumnStylesCollection
dgCols = DataGrid1.TableStyles(0).GridColumnStyles
For Each dgc In dgCols
If TypeOf dgc Is ColoredGridColumn Then
DirectCast(dgc, ColoredGridColumn).BeginUpdate()
End If
Next
' sample code to update database
For x As Integer = 0 To ds.Tables("Categories").Rows.Count - 1
Dim dr As DataRow = ds.Tables("Categories").Rows(x)
With dr
..BeginEdit()
..Item("CategoryName") = x.ToString
..EndEdit()
End With
Next
For Each dgc In dgCols
If TypeOf dgc Is ColoredGridColumn Then
DirectCast(dgc, ColoredGridColumn).EndUpdate()
End If
Next
End Sub
Here is the column style that add beginupdate and endupdate
Imports System.Drawing.Drawing2D
Public Class ColoredGridColumn
Inherits DataGridTextBoxColumn
Dim mForeColor As Color = Color.Black
Dim mBackColor As Color = Color.White
Public Property ForeColor() As Color
Get
Return mForeColor
End Get
Set(ByVal Value As Color)
mForeColor = Value
End Set
End Property
Public Property BackColor() As Color
Get
Return mBackColor
End Get
Set(ByVal Value As Color)
mBackColor = Value
End Set
End Property
Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics,
ByVal bounds As System.Drawing.Rectangle, ByVal source As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal
backBrush As System.Drawing.Brush, ByVal foreBrush As System.Drawing.Brush,
ByVal alignToRight As Boolean)
Dim brFore As Brush
Dim brBack As Brush
Dim cFore As Color
Dim cBack As Color
If Me.DataGridTableStyle.DataGrid.IsSelected(rowNum) Then
cFore = Me.DataGridTableStyle.SelectionForeColor
cBack = Me.DataGridTableStyle.SelectionBackColor
Else
cFore = ForeColor
cBack = BackColor
End If
brBack = New LinearGradientBrush(bounds, cBack, Color.White, 90, False)
brFore = New SolidBrush(cFore)
Dim bl As New Blend
bl.Factors = New Single() {0.0F, 0.1F, 0.5F, 0.7F, 0.7F, 0.5F, 0.3F, 0.2F,
0}
bl.Positions = New Single() {0, 0.1F, 0.2F, 0.5F, 0.6F, 0.7F, 0.8F, 0.9F,
1.0F}
DirectCast(brBack, LinearGradientBrush).Blend = bl
MyBase.Paint(g, bounds, source, rowNum, brBack, brFore, alignToRight)
End Sub
Public Shadows Sub BeginUpdate()
MyBase.BeginUpdate()
End Sub
Public Shadows Sub EndUpdate()
MyBase.EndUpdate()
End Sub
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, ByVal instantText
As String, ByVal cellIsVisible As Boolean)
MyBase.Edit(source, rowNum, bounds, [readOnly], instantText, cellIsVisible)
MyBase.TextBox.ForeColor = ForeColor
MyBase.TextBox.BackColor = BackColor
End Sub
End Class
Ken
---------------------------------
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:e3**************@TK2MSFTNGP11.phx.gbl...
Hi,
I found on the net that it is possible to use the BeginUpdate end
EndUpdate-methods with a DataGrid:
http://msdn.microsoft.com/library/de...pdatetopic.asp
Unfortunately it doesn't work with me: In some way I should make a derived
class from the DataGridColumnStyle but I'm not able to do it.
Des anybody knows how to do this?
Thanks a lot in advance!
Pieter