C# 获取一个ultragridcolumn';s实际宽度

C# 获取一个ultragridcolumn';s实际宽度,c#,winforms,infragistics,ultrawingrid,C#,Winforms,Infragistics,Ultrawingrid,如何在和UltraGrid中准确获取扩展的UltraGrid列的宽度 我有以下Windows窗体: public partial class Form1 : Form { public Form1() { InitializeComponent(); IEnumerable<string> test = new List<string>{DateTime.Now.ToString()}; this.ultra

如何在和UltraGrid中准确获取扩展的UltraGrid列的宽度

我有以下Windows窗体:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        IEnumerable<string> test = new List<string>{DateTime.Now.ToString()};
        this.ultraGrid2.DataSource = test;
        this.ultraGrid2.DisplayLayout.AutoFitStyle = AutoFitStyle.ExtendLastColumn;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        MessageBox.Show("The column width is " + this.ultraGrid2.DisplayLayout.Bands[0].Columns[0].Width);
    }
}
公共部分类表单1:表单
{
公共表格1()
{
初始化组件();
IEnumerable test=新列表{DateTime.Now.ToString()};
this.ultraGrid2.DataSource=test;
this.ultraGrid2.DisplayLayout.AutoFitStyle=AutoFitStyle.ExtendLastColumn;
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{
MessageBox.Show(“列宽为”+this.ultraGrid2.DisplayLayout.Bands[0].Columns[0].width);
}
}


无论我如何操作或调整窗体大小。
宽度
仍然提供相同的默认值。只有调整列的大小,它才会改变。在这种情况下,我认为宽度将接近表单本身的x大小。

如果将
AutoFitStyle
设置为
ExtendLastColumn
,则最后一列上的
width
属性不会反映列的实际宽度。如果将
AutoFitStyle
设置为
None
,则可以设置并读取列宽

然而,至少对于阅读来说,有一个变通方法:
在上面的示例中,只有一列,就可以获得该列的CellSizeResolved属性

UltraGridColumn column = grid.DisplayLayout.Bands[0].Columns[0];
Debug.WriteLine("Column width is " + column.CellSizeResolved.Width);

对我来说,
CellSizeResolved
不起作用。相反,我必须使用
((Infragistics.Win.Layout.ILayoutItem)列)