473,385 Members | 1,727 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,385 software developers and data experts.

DataGridView Optimization

Hi,

Is there a way to optimize the DataGridView in terms of drawing speed? The application that I'm building will need to use multiple datagridview controls which will get updated around every 100ms. A receiver will parse the data then pass it to the datagridview, but there is no way to know how many rows will be returned.

Right now I'm testing using 2 methods:
1. Generate the rows programmatically

Expand|Select|Wrap|Line Numbers
  1. private List<MyObject> dg1Data = new List<MyObject>();
  2. // ...
  3. private void UpdateDGV1() {
  4.   if (this.InvokeRequired) {
  5.     this.BeginInvoke((Action)delegate { UpdateDGV1(); });
  6.     return;
  7.   }
  8.  
  9.   int iRowHeight = 15;
  10.   if (dg1Data.Count != xDataGrid1.Rows.Count) xDataGrid1.Rows.Clear();
  11.   for (int i = 0; i < dg1Data.Count; i++) {
  12.     if (i >= xDataGrid1.Rows.Count) {
  13.       xDataGrid1.Rows.Add();
  14.       xDataGrid1.Rows[i].Height = iRowHeight;
  15.     }
  16.     xDataGrid1.Rows[i].Cells[0].Value = dg1Data[i].Value1;
  17.     xDataGrid1.Rows[i].Cells[0].Style.BackColor = Color.Black;
  18.     xDataGrid1.Rows[i].Cells[0].Style.ForeColor = Color.Red;
  19.     xDataGrid1.Rows[i].Cells[1].Value = dg1Data[i].Value2;
  20.     xDataGrid1.Rows[i].Cells[1].Style.BackColor = Color.Black;
  21.     xDataGrid1.Rows[i].Cells[1].Style.ForeColor = Color.Green;
  22.     xDataGrid1.Rows[i].Cells[2].Value = dg1Data[i].Value3;
  23.     xDataGrid1.Rows[i].Cells[2].Style.BackColor = Color.Black;
  24.     xDataGrid1.Rows[i].Cells[2].Style.ForeColor = Color.Blue;
  25.   }
  26. }
2. Using BindingSource

Expand|Select|Wrap|Line Numbers
  1. private List<MyObject> dg2Data = new List<MyObject>();
  2. private BindingSource dgv2Binder = new BindingSource();
  3. // ...
  4. public Form1() {
  5.   InitializeComponent();
  6.  
  7.   dgv2Binder.DataSource = dg2Data;
  8.   xDataGrid2.AutoGenerateColumns = false;
  9.   xDataGrid2.DataSource = dgv2Binder;
  10.   xDataGrid2.Columns[0].DataPropertyName = "MyValue1";
  11.   xDataGrid2.Columns[1].DataPropertyName = "MyValue2";
  12.   xDataGrid2.Columns[2].DataPropertyName = "MyValue3";
  13. }
  14. // ...
  15. private void UpdateDGV2() {
  16.   if (this.InvokeRequired) {
  17.     this.BeginInvoke((Action)delegate { UpdateDGV2(); });
  18.     return;
  19.   }
  20.  
  21.   dgv2Binder.ResetBindings(false);
  22. }
When I measures the time taken for each method to perform datagridview's OnPaint function, the first method somehow significantly faster (on average 20% faster).

So my first question is; did I do something wrong on updating the datasource? (because i thought using datasource is suppossed to be better?)

Then my second question, is there a way to improve the speed, or is there a better/alternative form control to use?

Thanks in advance.
Feb 18 '09 #1
1 3427
Hi,

Can someone help me please?

Thanks
Feb 23 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: DraguVaso | last post by:
Hi, I'm using the DataGridView in VB.NET 2.0. The DataSource is a Generic List of a custom class0: lstMyPersonnes = New List(Of clsPersonne). When I add a new clsPersonne to lstMyPersonnes,...
10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
2
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
0
by: jeastman - Hotmail | last post by:
Hello world Excuse, not to be written English and it helps me with a translator. I am new programming in C#. I made a control inheriting the DataGridView to be able to add controls done by...
3
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.