Question

How can I accurately get an expanded UltraGridColumn's width within and UltraGrid?

I have the following Windows Form:

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

what the form looks like

Regardless of how I manipulate or resize the form. The width still gives the same default value. Only if I resize the column will it change. In this case, I would think that the width would be close to the x size of the form itself.

Was it helpful?

Solution

If you set the AutoFitStyle to ExtendLastColumn the Width property on the last column doesn't reflect the actual width of the column. If you you set the AutoFitStyle to None you could set and read the column Width.

However, at least just for reading, there is a workaround:
In your example above, with only one column, you can get the CellSizeResolved property of the column

UltraGridColumn column = grid.DisplayLayout.Bands[0].Columns[0];
Debug.WriteLine("Column width is " + column.CellSizeResolved.Width);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top