Home Forums WinForms controls Xceed Grid for WinForms Autosize Column Width

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15857 |

    Sorry if something similar has been posted before. The search feature for this forum is broken.

    If I add a grid to a form, and add two columns that are not very wide, there is a huge chunk of space to the right of the columns. Is there a way get a specific column to expand its width to fill out all the white space?

    Imported from legacy forums. Posted by hepkat (had 3307 views)

    Xceed Support
    Member
    Post count: 5658

    There is no direct way to do that with our GridControl.

    Here is a basic implementation of what you could do.

    <code>
    private void Form1_Load( object sender, EventArgs e )
    {
    Column col1 = new Column( “Column1” );
    Column col2 = new Column( “Column2” );
    gridControl1.Columns.Add( col1 );
    gridControl1.Columns.Add( col2 );

    for( int i = 0; i < 20; i++ )
    {
    Xceed.Grid.DataRow row = gridControl1.DataRows.AddNew();
    foreach( Cell cell in row.Cells )
    {
    cell.Value = “Item ” + i.ToString();
    }
    row.EndEdit();
    }

    foreach( Column col in gridControl1.Columns )
    {
    col.WidthChanged += new EventHandler( col_WidthChanged );
    }

    //gridControl1.BorderStyle = BorderStyle.None;
    gridControl1.Columns[ gridControl1.Columns.Count – 1 ].Width = gridControl1.DisplayRectangle.Width – gridControl1.Columns[ 0 ].Width
    – gridControl1.RowSelectorPane.Width – gridControl1.FixedColumnSplitter.Width;
    gridControl1.Resize += new EventHandler( gridControl1_Resize );
    }

    void col_WidthChanged( object sender, EventArgs e )
    {
    if( ( ( Column )sender ).Index != gridControl1.Columns.Count – 1 )
    {
    gridControl1.Columns[ gridControl1.Columns.Count – 1 ].Width = gridControl1.DisplayRectangle.Width – gridControl1.Columns[ 0 ].Width
    – gridControl1.RowSelectorPane.Width – gridControl1.FixedColumnSplitter.Width;
    }
    }

    void gridControl1_Resize( object sender, EventArgs e )
    {
    gridControl1.Columns[ gridControl1.Columns.Count – 1 ].Width = gridControl1.DisplayRectangle.Width – gridControl1.Columns[ 0 ].Width
    – gridControl1.RowSelectorPane.Width – gridControl1.FixedColumnSplitter.Width;
    }
    </code>

    Imported from legacy forums. Posted by CharlesB (had 4448 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.