We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Sizing GridControl column to data size

Thread ID:

Created:

Updated:

Platform:

Replies:

117487 Oct 29,2014 10:43 AM Nov 10,2014 02:23 PM WPF 3
loading
Tags: GridControl
Craig Daniel
Asked On October 29, 2014 10:43 AM

I have a large dataset which is rapidly updating.
Each update triggers the QueryCellInfo in order to populate the cell.
I wish to size the column to the size of the data.
Calling ResizeColumnsToFit() after each update seems to performs very slowly.  I believe this is because this method is addressing the whole table, rather than just the cell (and thus column) which has updated.
So I tried manually sizing the column within the QueryCellInfo.  But this causes an exception
eg
private void OnGridQueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
        {
            ...
            var size = e.Style.CellModel.CalculatePreferredCellSize(e.Cell.RowIndex, e.Cell.ColumnIndex, e.Style, GridQueryBounds.Width);
 
            if (size.Width > grid.ColumnWidths[e.Cell.ColumnIndex])
            {
                grid.ColumnWidths[e.Cell.ColumnIndex] = size.Width;
            }
        }
Is there an event subsequent to the QueryCellInfo I can attach to which wouldn't cause this exception?
Or an alternate solution?



Kanimozhi Bharathi [Syncfusion]
Replied On November 3, 2014 12:45 PM

Hi Craig,

 

Thank you for using syncfusion products.

 

We have analyzed your query. You can achieve your requirement by using ResizeColumnsToFit() like the below code snippet.

 

Code Snippet:

 

private void Button_Click(object sender, RoutedEventArgs e)

{

    var row = this.grid.CurrentCell.RowIndex;

    var col = this.grid.CurrentCell.ColumnIndex;

    this.grid.Model.ResizeColumnsToFit(GridRangeInfo.Cell(row,col),GridResizeToFitOptions.None);

    this.grid.InvalidateVisual(true);

}

 

We have also prepared a simple sample based on your requirement. Please find the attachment below

 

Please let us know if you have any queries.

 

Thanks

Kanimozhi B


Attachment: Resizetofit_demo_31496542.zip

Craig Daniel
Replied On November 4, 2014 04:52 AM

As you can see from my original query I am already aware of ResizeColumnsToFit(), however in a situation where I have lots of cell updates this method performs poorly.

Kanimozhi Bharathi [Syncfusion]
Replied On November 10, 2014 02:23 PM

Hi Craig,

Apologize for the delay.

We have analyzed your query. But Currently GridControl do not have support to adjust the column width in QueryCellInfo event or any other subsequent events. However you can resize the particular cell by calling ResizeColumnsToFit method by passing argument as particular range instead of passing whole column or table like the below snippet as we have already explained in previous update.

this.grid.Model.ResizeColumnsToFit(GridRangeInfo.Cell(row,col),GridResizeToFitOptions.None);

Please let us know if you have any queries.

Thanks

Kanimozhi B


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;