Hello,
Thanks for your post on MDSN forum.
Based on my test, the column's width is fixed to the largest content within that column. When scrolling, the width is not changed. I've tried with the folloing code.
private void Form2_Load(object sender, EventArgs e)
{
string val = "test";
DataTable dt = new DataTable();
dt.Columns.Add("test");
for (int i = 1; i < 500; i++)
{
dt.Rows.Add(val);
val += "t";
}
this.dataGridView1.DataSource = dt;
this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader;
}
However, if you want to fix the column's size when scrolling, my suggestion is that we can disable the autosize functionality when the mouse left button is pressed, and enable the autosize when the left button is up.
Thanks,
Rong-Chun Zhang
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact
msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.