none
Silverlight Datagrid dynamic columns code behind CanUserResizeColumns are not working

    Question

  • In code behind dynamically generating columns in silverlight datagrid, columns are displaying good but columns are not resizing width in the browser.

    Property is added to the datagrid CanUserResizeColumns="True"

    Columns are generating from code behind of xaml.cs file in below format

    DataGridTextColumn gridTextColumn = new DataGridTextColumn();
    gridTextColumn.Header = columnData.HeaderName;

    gridTextColumn.MinWidth = Convert.ToDouble(columnData.ColumnWidth);
    gridTextColumn.Width = new DataGridLength(Convert.ToDouble(columnData.ColumnWidth), DataGridLengthUnitType.Star);
    gridTextColumn.MaxWidth = Convert.ToDouble(columnData.ColumnWidth);
    gridTextColumn.CanUserResize = true;

    Please help me to solve this issue of Datagrid column width resize in the browser not working.

    Thanks,

    Lokesh

    Tuesday, February 07, 2017 8:56 AM

Answers

  • Hi Lokesh,

    I'm glad that you have solved your issue and thanks for sharing your solution here. Please mark the helpful reply as answer, which is benefit to other communities who has the same issue.

    If any questions in future, please feel free to come back to our forum.

    Best Regards,
    Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by LokeshYVS Monday, February 13, 2017 8:52 AM
    Monday, February 13, 2017 1:24 AM
    Moderator

All replies

  • Hi Lokesh,

    According to your code, I create a sample project which generate a DataGrid in code behind. The default value for CanUserResize is true. Because when I doesn't set this value in my code, I could change the column width with my mouse.

    Then after I change my code based your code snippet, I still could resize the column width.

    But I found that you set column Width, MinWidth and MaxWidth for the DataGrid columns. If they are in different value, for example, Width = 100, MinWidth =80 and ManWidth =200, I could resize the columns and the column's width are limited by these three width values. But if I set them as the same value, Width = MinWidth = MaxWidth = 100, I could not resize the column side any more.

    So please debug your code to check whether these three values are the same. Please set them in different values which let the column could be resized.

    Best Regards,
    Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 08, 2017 7:33 AM
    Moderator
  • Hi Weiwei,

    I solve the issue,  problem with maxwidth property, maxwidth property stopping column resizing it fixed width of the column.

    I removed MaxWidth and MinWidth from my code and added only Width property

    gridTextColumn.Width = new DataGridLength(Convert.ToDouble(columnData.ColumnWidth));

    working fine

    Thanks for the quick reply. Weiwei

    Regards,

    Lokesh

    Thursday, February 09, 2017 3:32 PM
  • Hi Lokesh,

    I'm glad that you have solved your issue and thanks for sharing your solution here. Please mark the helpful reply as answer, which is benefit to other communities who has the same issue.

    If any questions in future, please feel free to come back to our forum.

    Best Regards,
    Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by LokeshYVS Monday, February 13, 2017 8:52 AM
    Monday, February 13, 2017 1:24 AM
    Moderator