Home Forums WinForms controls Xceed Grid for WinForms GridControl with Autoheigth

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • Xceed Support
    Member
    Post count: 5658
    #14470 |

    Hello,

    I’m new to the Xceed grid Control and therefore my knowledge about the grid control is limited. So perhaps my question is already discussed in any other forum or there is a property or function which solves my problem.

    To the problem itself:
    I have in my windows form a table control which is bind to a dataset. The count of the rows included in the set is dynamic, so the number of shown rows in the control is variable.
    Now I want to fit the size of the grid control to the heigth of the rows and the header.
    Now my idea was to use the DataRowsChanged event and calculate the heigth of each shown row and set the heigth of the control automatically.
    Unfortunatly I do get an error while opening the control: “An attempt was made to bind the grid to a data source while in an invalid state.”

    Please find used code below:

    private void gridControlNodes_DataRowsChanged(object sender, System.EventArgs e)
    {
    int heigth = 0;
    ///Calculate new height of the datagrid
    if (!gridControlNodes.InBatchInitialization)
    {
    foreach(Xceed.Grid.Rows row in gridControlNodes.DataRows)
    {
    heigth += row.Height;
    }
    gridControlNodes.Height = heigth + 30;
    }
    }

    Do you have any idea’s how I can solve this or are there any other solutions for a autosized grid control?

    Thanks in advance.
    Frank Weingaertner

    Imported from legacy forums. Posted by Frank (had 1939 views)

    User (Old forums)
    Member
    Post count: 23064

    This works fine here. How and where do you bind the grid? Does your application run when not subscribing to this event?

    Note that you should also loop for the FixedFooterRows and FixedHeaderRows so that all rows are taken into account to calculate the height of the grid.

    Xceed.Grid.Collections.RowList list = gridControl1.FixedFooterRows;
    foreach( Xceed.Grid.Row row in list )
    {
    Heath += row.Height;
    }
    list = gridControl1.FixedHeaderRows;
    foreach( Xceed.Grid.Row row in list )
    {
    Heath += row.Height;
    }

    Imported from legacy forums. Posted by André (had 3236 views)

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