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

DataGridView column autoresize hangs in virtual mode

VSE 2005 .NET 2 WinForms

I have DataGridView in virtual mode containing huge number of rows.
When user double clicks in column separator line in grid header, application
hangs: grid tries to read all rows!

How to force DataGridView to resize column only by using visible lines in
screen ?

I tried
AutoResizeColumns(DataGridViewAutoSizeColumnsMode. DisplayedCellsExceptHeader);

but this did not help.

Andrus.
Oct 16 '07 #1
2 6957
Andrus,

Well, the line that you displayed should do that. Can you show some
code/example of where it doesn't? A full example, of course.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andrus" <ko********@hot.eewrote in message
news:eQ**************@TK2MSFTNGP05.phx.gbl...
VSE 2005 .NET 2 WinForms

I have DataGridView in virtual mode containing huge number of rows.
When user double clicks in column separator line in grid header,
application hangs: grid tries to read all rows!

How to force DataGridView to resize column only by using visible lines in
screen ?

I tried
AutoResizeColumns(DataGridViewAutoSizeColumnsMode. DisplayedCellsExceptHeader);

but this did not help.

Andrus.

Jan 13 '08 #2
Well, the line that you displayed should do that. Can you show some
code/example of where it doesn't? A full example, of course.
Steps to reproduce:

1. Run code below
2. Double click in grid header in separation line between columns 1 ja 2

Observed:

CPU usage goes to 100% for a long time.

Andrus.

// modified virtual mode sample from Chris Sells book
using System;

using System.Windows.Forms;

using System.Collections.Generic;

class test {

[STAThreadAttribute()]

public static void Main() {

Application.Run(new VirtualModeForm());

}

}

class VirtualModeForm : Form {

private List<DataObjectm_Data = new List<DataObject>();

private List<boolm_Visited = new List<bool>();

DataGridView m_Grid = new DataGridView();

public VirtualModeForm() {

Controls.Add(m_Grid);

m_Grid.CellValueNeeded += OnCellValueNeeded;

InitData();

InitGrid();

}

private void InitData() {

for (int i = 0; i < 1000001 + 1; i++) {

m_Visited.Add(false);

DataObject obj = new DataObject();

obj.Id = i;

obj.Val = 2 * i;

m_Data.Add(obj);

}

}

private void InitGrid() {

m_Grid.Dock = DockStyle.Fill;

m_Grid.AutoResizeColumns(DataGridViewAutoSizeColum nsMode.DisplayedCellsExceptHeader);

m_Grid.VirtualMode = true;

m_Grid.ReadOnly = true;

m_Grid.ColumnCount = 3;

m_Grid.Rows.Add();

m_Grid.Rows.AddCopies(0, 1000000);

}

private void OnCellValueNeeded(object sender,

DataGridViewCellValueEventArgs e) {

m_Visited[e.RowIndex] = true;

if (e.ColumnIndex == 0) {

e.Value = m_Data[e.RowIndex].Id;

} else if (e.ColumnIndex == 1) {

e.Value = m_Data[e.RowIndex].Val;

} else if (e.ColumnIndex == 2) {

Random rand = new Random();

e.Value = rand.Next();

}

}

}

public class DataObject {

private int m_Id;

private int m_Val;

public int Val {

get { return m_Val; }

set { m_Val = value; }

}

public int Id {

get { return m_Id; }

set { m_Id = value; }

}

}
Jan 14 '08 #3

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

Similar topics

1
by: AMD Desktop | last post by:
Hi, I have a problem and not sure what is going on here, may be the coding is not proper. This is a simple page with calendar events. Everything works fine until I click on View Week link. Then...
4
by: Chris Botha | last post by:
VS2005 and I have a DataTable displayed in a DataGridView that needs custom sorting, with the DataSource of the grid set to the DataTable and the SortCompare event just won't fire. Then I found...
2
by: lord.zoltar | last post by:
I have a DataGridView that has potentially several hundred rows (possibly a thousand or two). I'd like for each row to have the proper height to accomadate the text in the row. I tried setting the...
0
by: Paul | last post by:
I'm creating a UserControl that uses a DataGridView in virtual mode. It was working fine other than a few bugs. After I fixed those few bugs, I broke it. I have a cache of 50 records. The...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a...
0
by: Richard Charts | last post by:
After searching the forums, newsgroups, and web, I cannot seem to find a straight answer. Is it possible to use a bounded datasource in virtual mode on a datagridview? I would like to have the...
1
by: slg | last post by:
I am using virtual mode for datagrid. After i set the rowcount property to 16000, I am receiving datagridview 's CellValueNeeded event 16000 times for each row. This is causing the application to...
4
by: Michel Walsh | last post by:
Someone has an example, C#, about how to set the cell(int row, int col) as the current cell for a DataGridView. The example, in the help file, about DataGrid.CurrentCell Property (Set) ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.