隐藏与标签不匹配的所有行

编程入门 行业动态 更新时间:2024-10-24 11:14:38
本文介绍了隐藏与标签不匹配的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想隐藏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();

更多推荐

隐藏与标签不匹配的所有行

本文发布于:2023-10-26 23:18:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531642.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不匹配   标签

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!