在C#中的datagridview中手动更改列宽 [英] manually changing column width in datagridview in c#

查看:396
本文介绍了在C#中的datagridview中手动更改列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个事件,该事件在用户通过拖动列分隔符手动更改DataGridView中列的宽度时触发.

我正在使用DataGridView,其中将AutoSizeColumnMode设置为填充所有列.


请给我解决方法



thnks

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

推荐答案

为此页面添加书签: ^ ]

应该可以帮助您的一个因素是:
DataGridView.ColumnDividerWidthChanged事件 [
Bookmark this page for yourself: DataGridView Events[^]

The one that should help you out is:
DataGridView.ColumnDividerWidthChanged Event[^]


这是DataGridView
ColumnWidthChanged事件
调整父窗体的大小时,您必须过滤掉此事件触发.使用ResizeBegin设置一个正在调整大小的标志,使用ResizeEnd重置该标志.

另外,您还必须知道用户正在调整哪一列的大小.为此使用MouseDown事件.

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.

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;
        }
    }
}


这篇关于在C#中的datagridview中手动更改列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆