Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datagridview column limit

I have a datagridview table that I need to display some data in. In certain instances, I exceed the column number limit and get the following error:

Sum of the columns' FillWeight values cannot exceed 65535

Is there any other tool that I could use to overcome this constraint?

like image 331
sunil shankar Avatar asked May 12 '13 13:05

sunil shankar


People also ask

How to set max length of DataGridView column in c#?

Solution 1Use the MaxInputLength property of the DataGridViewTextBoxColumn.

What is Fillweight?

FILL WEIGHT shall refer to the weight of a cooked tuna Loin portion that is placed in each can prior to the addition of water and/or Hydrolyzed Protein, and prior to the sealing of the can.


2 Answers

Open a grid event columnAdded.

private void dataGridViewName_ColumnAdded(object sender, DataGridViewColumnEventArgs e)
{
    e.Column.FillWeight = 10;    // <<this line will help you
}
like image 138
user5245162 Avatar answered Oct 06 '22 18:10

user5245162


The default fill weight for a column in the DataGridView is 100. This combined with the maximun combined fill weight for the grid of 65535 means that with AutoGenerateColumns set to true you cannot have more than 655 columns in your data source.

If you need more columns than this then the only solution is to set AutoGenerateColumns for the grid to false, and then manually add the columns with a different fill weight (I'm not sure if 0 is a valid fill weight, so you may need to use 1).


It might be worth your while considering a different design - having so many columns in a DataGridView won't be very usable, the performance of the DataGridView is only tuned for up to 100 columns (I got that figure from this forum post by the DataGridView program manager)

like image 32
David Hall Avatar answered Oct 06 '22 19:10

David Hall