Click here to Skip to main content
15,882,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am looking for an event which is fired when a user manually changes the width of a column in DataGridView by dragging the column divider.

I am using DataGridView, where AutoSizeColumnMode is set to fill for all columns.


pls give me solution



thnks
Posted

Bookmark this page for yourself: DataGridView Events[^]

The one that should help you out is:
DataGridView.ColumnDividerWidthChanged Event[^]
 
Share this answer
 
It is the ColumnWidthChanged event of the DataGridView

You'll have to filter out this event firing when parent form is resized. Use ResizeBegin to set a flag that form is resizing and ResizeEnd to reset the flag.

Also you'll have to know which column is being resized by user. Use MouseDown event for this.

C#
private void dataGridView_MouseDown(object sender, MouseEventArgs e)
{
    for (int i = 0; i < dataGridView.ColumnCount; i++)
    {
        if (dataGridView.GetColumnDisplayRectangle(i, true).Contains(e.Location))
        {
            columnBeingResized = dataGridView.Columns[i];
            break;
        }
    }
}
 
Share this answer
 
v4
Comments
amitthakkar1987 3-Aug-10 5:39am    
please give me description about "columnBeingResized"
Dima Popov 3-Aug-10 8:04am    
That's a variable you should define in your form class.
DataGridViewColumn columnBeingResized;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900