C1FlexGrid Windows Forms Column Width

Posted by: mwebster on 31 January 2019, 12:07 pm EST

    • Post Options:
    • Link

    Posted 31 January 2019, 12:07 pm EST

    I am working with the C1FlexGrid for Windows Forms and need to figure out how to auto-resize the columns to cause the Flexgrid to fill the available horizontal space. I saw that there is an “Expand Last Column” property but that looks terrible if the last column is not something like a text field that can be expanded in that way. In the application I am working on, this last column contains a dollar value and expanding it to fill all of the space looks terrible. I need to get all of the columns to resize proportionally in the way that the default .NET DataGridControl does. Does anyone have any suggestions?

  • Posted 1 February 2019, 3:02 am EST

    Hello,

    Please use the following line of code to resize all of the columns proportionally.

    
      private void AutoSize()
            {
                var gridWidth = c1FlexGrid1.Width;
                gridWidth =( gridWidth - c1FlexGrid1.Cols[0].Width);
                for (int i =1;i<c1FlexGrid1.Cols.Count-1;i++)
                {
                    c1FlexGrid1.Cols[i].Width = gridWidth / 4;
                }
                
            }
    
    

    Hope it helps.

    Thanks.

  • Posted 1 February 2019, 1:00 pm EST

    You could also use the “c1FlexGrid1.Cols[i].StarWidth” property, introduced in some 2018 version: set it to “*” for all columns which should fill the available width.

    Best regards

    Wolfgang

  • Posted 1 February 2019, 2:30 pm EST

    That did the trick! Thanks.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels