在datagridview中隐藏行 [英] Hiding row in datagridview

查看:384
本文介绍了在datagridview中隐藏行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想隐藏该行,如果它有一个单词....





I want to hide the row if it has a certain word in it ....


foreach (DataGridViewRow dr in CustOrdersDGV.Rows)
{
    if (dr.Cells[6].Value.ToString() == "hot")
    {
        dr.Visible = false;
    }
}







但所有细胞无论如何显示



我尝试过:






But all of the cells show regardless

What I have tried:

<pre>                foreach (DataGridViewRow dr in CustOrdersDGV.Rows)
                {
                    if (dr.Cells.Count > 6)  // validate the index

                    if (dr.Rows[6].Value.ToString() == "hot")
                    {
                        dr.Visible = false;
                    }
                }

推荐答案

您似乎在if语句中调查行而不是单元格。此外,您希望单元格值完全热,而不仅仅是包含它。尝试使用

You seem to investigate rows instead of cells in the if statement. Also you expect to the cell value to be exactly "hot", not just contain it. Try using
if (dr.Cells[6].Value.ToString().ToLower().Contains("hot"))
{
   dr.Visible = false;
}


这篇关于在datagridview中隐藏行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆