Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
604
Resizing the width of the columns
posted

I've seen a lot of posts here on the issue of resizing the width of the columns at runtime but did't find the answer I'm looking for.

I have the following request:

When the user double-clicks the label of the column , th column shoul resize to let's say 300, and this is the code I'm using to acheive this:

 

 

 

 

private void onHeaderDoubleClick(object sender, RoutedEventArgs e)

{

 

 

LabelPresenter labelPresenter = (sender as LabelPresenter);

labelPresenter.Field.Settings.LabelWidth = 300;

labelPresenter.Field.Settings.CellWidth = 300;

e.Handled =

true;

}

Simple, but it doesn't work as expected. The behaviour I'm seeing is as follows:

1. Uer double-clicks the 1st time --> the column is resized to 300

2. User drags the field separator and resizes the width of the column to let's say 50

3. User coubld-clicks again --> expected result : the column is resized back to 300 , but nothing happens. The column is not resized to 300.

After a short investigation, in debugger I saw  that what the user resizes the field only the CellWidthResolved and LabelWidthResolved properties of the Field change, but the CellWidth and the LabelWith properties of FieldSettings stay the same.

Is it a bug? Am I doing something wrong here? I thought it would be easy, straight forward.

I have v9.1 version installed

Pls, help.

Parents
No Data
Reply
  • 69686
    Suggested Answer
    posted

    Hello,

    When you resize the Field the first time, the XamDataGrid saves it as customization.

    In order for this to be working as you expect, you have to clear this particular customization. Please try with the following extra line of code:

    private void onHeaderDoubleClick(object sender, RoutedEventArgs e)

            {

                xamDataGrid1.ClearCustomizations(CustomizationType.FieldExtent);

                LabelPresenter labelPresenter = (sender as LabelPresenter);

                labelPresenter.Field.Settings.LabelWidth = 300;

                labelPresenter.Field.Settings.CellWidth = 300;

                e.Handled=true;

            }

    Hope this helps.

Children