简体   繁体   English

如何自动调整datagridview行的大小以摆脱空白的灰色区域

[英]How to autosize datagridview rows to get rid of blank gray areas

Hello I have a vbnet windows forms application and I'm looking for a simple way of deleting the blank areas of a datagridview. 您好,我有一个vbnet Windows窗体应用程序,并且我正在寻找一种删除datagridview的空白区域的简单方法。 I know there is a simple way of doing this for columns using the 我知道有一种简单的方法可以使用

DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill

It seems sort of strange to me that there isn't a similar way of dong this for the rows. 对于行来说,没有类似的方法可以让我感到奇怪。 Does anyone know of a simple way of fixing this issue? 有谁知道解决此问题的简单方法? I greatly appreciate any help or suggestions you may offer. 非常感谢您提供的任何帮助或建议。

在此处输入图片说明

If you dont want empty rows in your grid, do not load them in the grid. 如果您不希望网格中有空行,请不要将其加载到网格中。

Grids are usually filled by setting its' DataSource property. 网格通常是通过设置其DataSource属性来填充的。 This may be anything that implements IList, and a few other things like a DataTable/DataSet. 这可能是实现IList的任何东西,也可能是其他一些东西,例如DataTable / DataSet。 If you dont want them in the grid, dont put them in the object that you used as your DataSource. 如果您不希望它们出现在网格中,请不要将它们放在用作数据源的对象中。

If you used some type of list the implements INotifyCollectionChanged, like an ObservableCollection or BindingSource, you can Remove the items after they are added. 如果您使用实现INotifyCollectionChanged的某种类型的列表(例如ObservableCollection或BindingSource),则可以在添加项目后Remove它们。

要摆脱该“空白”区域,您需要调整网格的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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