【问题标题】:getting an ultragridcolumn's actual width获取超网格列的实际宽度
【发布时间】:2013-01-24 16:51:49
【问题描述】:

如何在 UltraGrid 和 UltraGrid 中准确获取展开的 UltraGridColumn 的宽度?

我有以下 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);
    }
}

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

【问题讨论】:

    标签: c# winforms infragistics ultrawingrid


    【解决方案1】:

    如果将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)column).PreferredSize.Width
    猜你喜欢
    • 2011-08-18
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    相关资源
    最近更新 更多