如何使用if条件过滤datagridview [英] How to filter datagridview with if condition

查看:131
本文介绍了如何使用if条件过滤datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用组合框过滤我的datagridview。我想得到一条消息,告诉我无法找到选择的值,因为列名不会在datagridview中退出。

我的库存是第二个if if语句。



Hi I am filtering my datagridview using a combobox. I wanna get a message telling me that the choosen value can't be found because the column name doesn't exit in the datagridview.
where I'm stock is the second else if statement.

private void cbFilterEU_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            string check = cbFilterEU.SelectedItem.ToString();
            if (check == "All")
            {
                MessageBox.Show("All Data !!!");

            }

            else if (cbFillFilterEIU.SelectedItem != null)
            {
                //Check an see what's in the dgv
                DataView dv = new DataView(dt);
                // now filter
                dv.RowFilter = " [Areacode] = " + cbFilterEU.Text.Trim();
                MessageBox.Show("AREACODE");
                datagridview1.DataSource = dv;
            }
		else if
{
/* Wanna look through the datagridview for the column name and if not present show message
                MessageBox.Show("Can't find the column");
             */
}





我试过这样的事但没有成功





I tried something like this but no success

//else if (cbFilterEU.SelectedItem != null && datagridview1 == null)
           //{
           //    MessageBox.Show("Can't find the column");
           //}

推荐答案

在SelectedItem不为空的情况下,不会调用你的最后一个else if
Your last "else if" will not be called in the case the SelectedItem is not null


您好b $ b

您可以尝试



datagridview1 .Rows.Count< = 0;




而不是 datagridview1 == null
Hi
You can try

datagridview1 .Rows.Count<=0;


instead of datagridview1 == null


这篇关于如何使用if条件过滤datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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