Percentage column widths of DataGridView

Is there a way to give each column in a DataGridView a percentage width of the overall grid? I am currently using a fixed width, but would like to give one column 15% wide, another 25% wide, etc., so that 100% of the table is filled and resized using the grid.

+6
source share
3 answers

Try using the DataGridViewColumn.FillWeight property. Basically you assign a weight to each column, and the columns change according to these weights. The MSDN argument is not that big. See the article below for a better explanation -

Presenting data using the DataGridView control in .NET 2.0-Automatic Column Sizing

+15
source

You can use a value converter
This subtracts the parameter, but you can split it into the parameter.

<local:WidthConverter x:Key="widthConverter"/> <GridViewColumn Width="{Binding ElementName=lvCurDocFields, Path=ActualWidth, Converter={StaticResource widthConverter}, ConverterParameter=100}"> [ValueConversion(typeof(double), typeof(double))] public class WidthConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // value is the total width available double otherWidth; try { otherWidth = System.Convert.ToDouble(parameter); } catch { otherWidth = 100; } if (otherWidth < 0) otherWidth = 0; double width = (double)value - otherWidth; if (width < 0) width = 0; return width; // columnsCount; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } 
+1
source

just create a skin file. and apply it through web configuration

-3
source

All Articles