简体   繁体   English

C#-获取datagridview中每列的宽度总和

[英]C# - Get the sum of the total amount of width for each column in datagridview

Is there any faster way other than looping through each column and increment a variable with their width? 除了遍历每一列并增加其宽度的变量以外,还有没有其他更快的方法?

For now this is the best solution, but is pretty slow: 目前,这是最好的解决方案,但速度很慢:

int contentWidth = 0;
foreach (DataGridViewColumn column in grid.Columns) {
    contentWidth += column.Width;
}

这将返回可见列的长度:

contentWidth = grid.Columns.GetColumnsWidth(DataGridViewElementStates.Displayed);

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

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