简体   繁体   中英

Windows Form DataGridView AutoSizing

My friend and I are trying to do some Autosizing with our DataGridView. Right now, we have set the AutoSizeColumn to "Fill" which we want to do as it fits the box. Now, what we don't want, is that it resizes all the Columns to the same size. What I mean with this is, that the Column "ID" and "Name" is the same size.

In ID there might be "5" which have A LOT of extra space while in Name "//SomeRandomLongName//" don't have enough space to show the full name. Is there a way to give ID less space while giving "Name" more space while still having it on "Fill"?

Hope you can help. Nicklas.

You can use FillWeight property of DataGridViewColumn to control the proportions of columns whose AutoSizeMode property is set to . 的列的比例。 Eg in your case when you know for sure that ID column will store only short (in respect to names) numbers you can decrease its fill weight. If you set FillWeight of ID column to lets say 1 and FillWeight of Name column to 5 that will mean that Name column will have five times more space than ID column and both columns will still resize themselves to fill all the available space.

The actual values of this property are not important by themselves only comparative to each other ie you can set them to 500 and 100 and have the same effect

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM