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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Sizing GridControl column to data size

Thread ID:

Created:

Updated:

Platform:

Replies:

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

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 05:45 PM UTC

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 09:52 AM UTC

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 07:23 PM UTC

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.

Warning Icon 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.Close Icon

;