Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在开发一个具有 5 列 DataGridView 的 MS Office 加载项。是否可以只显示尽可能多的列以适合侧边栏,但是当用户重新调整加载项侧边栏的大小时,添加更多或删除列,因为它们有空间?
您可以使用 Datagridview 的 Resize 事件并添加和删除(或设置可见性)所有不需要的行。
我猜您的列具有给定的大小,并且不会自动调整大小。
在这种情况下,您可以:
int columnsToShow = (int)(dataGridView.Size.Width / columnWidth);
现在添加足够的行以匹配所需的数量/删除所有过多的行或设置可见性