Reputation: 11607
Or is there any better suited 3rd party control for this purpose?
Upvotes: 3
Views: 4030
Reputation: 3628
You're missing that the FillWeight variable takes a floating point number not an integer, so 0.5f or 0.01f would do (the latter would allow up to 6553500 columns in theory). Unfortunately, creation is very slow (at least for me, increasingly past around 1000 columns; 10,000 cols takes about 20 seconds). Perhaps the VirtualMode others have suggested is worth a shot.
For what it's worth, here is the code I use to create an x by y size table of empty cells. Perhaps someone can optimize the speed further:
private void createDGVcells(DataGridView dgv, int columns, int rows) {
// Optimization:
dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; // Massive speed up if high column count
dgv.ScrollBars = ScrollBars.None; // Apx. 75% speedup for high row count
dgv.AllowUserToAddRows = false; // Further 50% apx speedup when creating rows
dgv.ReadOnly = true; // Small apx. 50ms latency speedup?
// First clear any existing cells, should they exist:
if (dgv.DataSource != null) dgv.DataSource = null;
else {
dgv.Rows.Clear();
dgv.Columns.Clear();
}
// Create the first row (the columns):
DataGridViewColumn[] dgvc = new DataGridViewColumn[columns];
for (int i = 0; i < dgvc.Length; ++i) {
DataGridViewColumn dg = new DataGridViewTextBoxColumn();
dg.FillWeight = 0.1f; // Allows up to 655350 columns in theory
dgvc[i] = dg;
}
dgv.Columns.AddRange(dgvc);
// Add all the rows (very quick)
for (int j = 0; j < rows - 1; j++) dgv.Rows.Add();
// Optional to turn these back on
dgv.ReadOnly = false;
dgv.AllowUserToAddRows = true;
dgv.ScrollBars = ScrollBars.Both;
dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
}
Upvotes: 1
Reputation:
Xceed's DataGrid for WPF can do this easily and uses both column and UI virtualization. Check out their live demo. You can populate the demo with as many columns and rows needed to test perf. http://xceed.com/Grid_WPF_Demo.html
Upvotes: 0
Reputation: 7208
I know that DevExpress XtraGrid supports, in theory, Int32.MaxValue rows or columns in the grid. In this case, the limit is the system memory not the grid.
But do you really need to display so much data?
Upvotes: 9
Reputation: 5687
Use a virtual list (loads only the rows that are visible). I'm not sure that WinForms ListView has a virtual mode but the WPF one does.
So create a WPF user control and set it up for VirtualMode = True and host that user control on your WinForms client with an ElementHost container.
Sorry I can't be more specific, I don't have the code to hand.
Ryan
Upvotes: 2
Reputation: 117250
Short answer: Dont do it!
Long answer: Change the FillWeight to 10 or less (default is 100). The limit you are reaching is due to the total FillWeight exceeding 64K x 100 (who knows why that is a limit).
Upvotes: 2