Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3455
How can I set same width for all columns at run time?
posted

Hi,

How can I set all column with same width at run time.

I have a button in my application, when the user press this button above mentioned functionality must work.

regards,

pgr2007

Parents
  • 45049
    posted

    Here's some code I'd use for this.  I haven't tested it, but it illustrates the approach.  You'd call this method from your button click, passing in a reference to your WinGrid as well as the width you want set on all columns.

    using Infragistics.Win.UltraWinGrid;
    ...
    private void ResetColumnWidths(UltraGrid grid, int width)
    {
        foreach (UltraGridBand band in grid.DisplayLayout.Bands)
        {
            foreach (UltraGridColumn column in band.Columns)
            {
                column.Width = width;
            }
        }
    }

    Assumptions made here:

    • You're using an AutoFitStyle of None.  Using either ExtendLastColumn will resize the last column automatically, and using ResizeAllColumns means that, as you change one column's width, other coulmns' widths will be adjusted to fill the remaining space.
    • You want to affect all bands equally.  If you instead want to only affect a single band, you can modify this method to either take an UltraGridBand object as a parameter, or to always affect a specific band (such as Bands[0]) instead of looping through all bands in the grid.
    • You either don't care whether or not the columns exactly fill all the available space in the grid, or you choose a width that will do this for you.
Reply Children