473,320 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 2524
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Etienne | last post by:
Hi, I have a form containing 2 TreeViews. When I click on a button, items are transfered from the left tree to the right tree, which causes flickering. In order to remove such flickering, I...
3
by: Ajay Krishnan Thampi | last post by:
I have a slight problem implementing 'drag and drop' from a datagrid to a tree-view. I have pasted my code below. Someone please advice me on what to do...pretty blur right now. ==code== ...
6
by: VM | last post by:
I have a 35000 line datagrid and updating one field in all 35000 rows takes an eternity. How come? Since I don't have the datasource available (it may be a table or view), in my example I do it...
2
by: shumaker | last post by:
A few form controls have a Beginupdate function that stops the control from being painted until endupdate is called, and I'm wondering if anyone has an idea of how to implement a function like this...
3
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint...
6
by: Agnes | last post by:
I understand it is impossible, but still curious to know "Can I freeze several column in the datagrid, the user can only scroll the first 3 columns (not verical), for the rest of the coulumn, it is...
4
by: skOOb33 | last post by:
I successfully autosized the columns and rows on my Datagrid, and am now facing another issue. Having the sorting ability by clicking the column headers is key, but when I do that, it resizes all...
1
by: SeeSharp Bint | last post by:
Hi, Am i able to do the datagrid equivalent of beginupdate endupdate while i'm sorting rows in a datagrid please. I dont want it redrawing everything while I do the work as its so slow. thanks
4
by: Anil Gupte | last post by:
I am using the following code: URLListBox.BeginUpdate() URLListBox.DataSource = DSContent '.Tables("ContentSites") URLListBox.DisplayMember = "ContentSites.SiteName" URLListBox.ValueMember =...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.