gpt4 book ai didi

c# - 在 datagridview winforms 中隐藏行的快速方法

转载 作者:太空宇宙 更新时间:2023-11-03 20:56:20 24 4
gpt4 key购买 nike

我正在尝试制作一个窗口窗体应用程序,我需要在其中非常频繁地隐藏和显示 datagridView 的行。目前正在使用循环

for (int i=0;i<grid.Rows.Count;i++){
grid.Rows[i].Visible = false;
}

但这让我的 UI 太慢了,有没有更快的方法来做到这一点?提前致谢。

最佳答案

您可以在将所有行存储在列表中后删除所有行,并根据需要将它们添加回去:

List<DataGridViewRow> rows = null;


// prepare list
rows = new List<DataGridViewRow>();
// copy rows to list
rows.AddRange(dataGridView1.Rows.Cast<DataGridViewRow>());
// remove them all
dataGridView1.Rows.Clear();


// add them back:
dataGridView1.Rows.AddRange(rows.ToArray());
// clean up
rows.Clear();

关于c# - 在 datagridview winforms 中隐藏行的快速方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50229616/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com