本文介绍了隐藏与标签不匹配的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想隐藏datagrid中与Access.text标签中的文本不匹配的所有行,我该如何做到这一点?
I want to hide all rows in datagrid which do not match the text in Access.text label, How would I accomplish this?
foreach (DataGridViewRow row in productionDGV.Rows) { if (row.Cells[4].Value.ToString() == Access.Text) { row.Visible = true; } else if (row.Cells[4].Value.ToString() != Access.Text) { row.Visible = false; } }我尝试了什么:
What I have tried:
foreach (DataGridViewRow row in productionDGV.Rows) { if (row.Cells[4].Value.ToString() == Access.Text) { row.Visible = true; } else if (row.Cells[4].Value.ToString() != Access.Text) { row.Visible = false; }推荐答案
通常,您可以通过将Visible属性设置为true来将行设置为不可见。但是,您可能需要在设置属性时暂停绑定。请考虑以下内容,将 myDataTable 替换为您用作数据源的实际对象。 In general you can set the row as invisible by setting the Visible property to true. However, you may need to suspend the binding while setting the property. Consider the following, replace the myDataTable with the actual object you use as the data source. BindingContext[myDataTable].SuspendBinding(); foreach (DataGridViewRow row in this.productionDGV.Rows) { if (row.Cells[4].Value.ToString() != Access.Text) { row.Visible = false; } } BindingContext[myDataTable].ResumeBinding();
更多推荐
隐藏与标签不匹配的所有行
发布评论