If you add a DataGridTableStyle to your Datagrid, then you can use the ColWidth property of the GridColumnStyles to set the width of each column. To dynamically set these widths as the grid is resized, you can handle the SizeChanged event of the the DataGrid. In your handler, you can compute the width of each column by dividing the client width minus the width of the row header column by the number of columns. Now there are a couple of technical points. You have to adjust for a possible vertical scrollbar. And, you have to adjust things for possible integer rounding in the calculations. To handle this last problem, the attached samples (both VB and C#) apply the single computed width to all but the last column. And this last column is just given all the space left. This means the last column may differ in width from the other columns by a couple of pixels.
WHY WE STAND OUT
- Blazor Competitive Upgrade
- Angular Competitive Upgrade
- JavaScript Competitive Upgrade
- React Competitive Upgrade
- Vue Competitive Upgrade
- Xamarin Competitive Upgrade
- WinForms Competitive Upgrade
- WPF Competitive Upgrade
- PDF Competitive Upgrade
- Word Competitive Upgrade
- Excel Competitive Upgrade
- PPT Competitive Upgrade
CONTACT US
- Fax: +1 919.573.0306
- US: +1 919.481.1974
- UK: +44 20 7084 6215
Toll Free (USA):
- 1-888-9DOTNET
- sales@syncfusion.com
Share with