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. Image for the cookie policy date

Need to reset GridDataControl column sizing to Auto after programmatically resetting visible columns

My gridDataControl is set with ColumnSizer=Auto in XAML and it initially displays  columns sized according to header / cell size as expected.
But when user picks new columns to display, I clear out the VisibleColumns and add new ones in .cs code.
But then it seems the 'Auto' format is lost, because all the columns display with a fixed size that is much larger than necessary.
How do I restore Auto column sizing in .cs code ?

5 Replies

AS Ambarish Srinivasan Syncfusion Team February 8, 2016 04:04 AM UTC

Hi Steve,

Currently we are working on your requirement and will provide the solution on February 8th, 2016.

Regards,
Ambarish.


JS Jayapradha S Syncfusion Team February 8, 2016 12:40 PM UTC

Hi Steve,

You can restore the Auto column sizer to grid by invoking RefreshAll() method as shown in the below code snippet,

Code Example:

private void AddColumns()       

        {

            this.syncgrid.VisibleColumns.Clear();

            this.syncgrid.VisibleColumns.Add(new GridDataVisibleColumn() { MappingName = "JobNumber", HeaderText = "Open Unit" });

            this.syncgrid.VisibleColumns.Add(new GridDataVisibleColumn() { MappingName = "ProductID" });

            this.syncgrid.VisibleColumns.Add(new GridDataVisibleColumn() { MappingName = "ProductName" });

            this.syncgrid.VisibleColumns.Add(new GridDataVisibleColumn() { MappingName = "Quantity" });

            this.syncgrid.ClearValue(GridDataControl.ColumnSizerProperty);

            this.syncgrid.ColumnSizer = GridControlLengthUnitType.Auto;

            this.syncgrid.Model.ColumnAutoSizer.RefreshAll();
        }


Please let me know if you have any further query.

Regards,
Jayapradha




SM Steve McWilliams February 8, 2016 03:22 PM UTC

I get error saying I cannot access internal method 'RefreshAll()' here


SM Steve McWilliams February 8, 2016 08:30 PM UTC

However, the problem seems to be fixed anyway  just by the first two lines, doing the ClearValue() and resetting sizer to auto.


JS Jayapradha S Syncfusion Team February 9, 2016 11:28 AM UTC

Hi Steve,

Yes, the reported auto column sizer problem will be fixed by clearing and resetting the value of column sizer as shown in our previous code example.

Regarding the query, I get error saying I cannot access internal method 'RefreshAll()' here:

In your version (10.3), RefreshAll method is not exposed for public use. As reset column sizer solves your problem, you can use the same.

Please let me know if you have any other concern.

Regards,
Jayapradha


Loader.
Live Chat Icon For mobile
Up arrow icon