471,056 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

DataGrid + BeginUpdate/EndUpdate

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
Nov 20 '05 #1
1 2327
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

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Etienne | last post: by
3 posts views Thread by Ajay Krishnan Thampi | last post: by
6 posts views Thread by VM | last post: by
2 posts views Thread by shumaker | last post: by
6 posts views Thread by Agnes | last post: by
1 post views Thread by SeeSharp Bint | last post: by
4 posts views Thread by Anil Gupte | last post: by
reply views Thread by leo001 | last post: by

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.