Hi,
I have a requirement where I need to set the width of a column to "Auto". I am able to do this from XAML code but couldn't find a way to set it from code behind.
Though, I am aware that to change the width I can use - column.Width = new ColumnWidth(3.5, true);
but with this approach I am not sure if the width can be set to "Auto".
Any suggestions on this is appreciated.
Thank You,
Raj
Hello Raj, In order to set the width of a column in XamGrid to Auto in code-behind, you can set the Width property of the respective column to ColumnWidthType.InitialAuto or ColumnWidthType.Auto. Code-behind: xamGrid.ColumnWidth = ColumnWidthType.InitialAuto; For more detailed information, you can take a look at Change Column Width Settings. If you require any further assistance on the matter, please let me know.
Hi Tacho,
The ColumnWidth property mentioned above is available at the XAMGrid level and I don't see it at the column level. My requirement is to set the width of specific column(s) to "Auto".
Thanks,
Hello Raj, Setting a specific width to any of the Columns can be done by casting the column to it's actual type and setting it's Width property respectively.
For example: (grid.Columns[0] as TextColumn).Width = ColumnWidth.Star;
(grid.Columns[1] as TextColumn).Width = ColumnWidth.Auto;
(grid.Columns[2] as TextColumn).Width = new ColumnWidth(60, false); If you require any further assistance on the matter, please let me know.
Thank You, Tacho. Worked for me.
Hello Raj,
Thank you for your feedback. I am glad to know that I was able to help you achieve the functionality you were looking for. I believe this thread can help other people looking for a similar solution.