如何从另一个表单中过滤datagridview [英] How to filter datagridview from another Form

查看:61
本文介绍了如何从另一个表单中过滤datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。所以我在Windows Forms中制作projekt并需要一点帮助。在我的第一个表单中,我将数据从本地sql数据库导入datagridvdiew。客户资金转账数据。现在我需要为我的DGV制作一个过滤器,例如显示所有客户数据,其中汇款超过1500美元。这样的查询可以不止一个所以我在buttonClick上调用另一个表单来输入所有过滤器参数。在ButtonClick上输入参数后,我需要过滤第一个Form中的DGV中的数据。但我不知道如何从另一个表格改变DGV。我试图通过这种方式调用form1:

Form form1 = new Form();但我还是不能达到DGV。谁可以帮我这个?

Hello guys. So I am making projekt in Windows Forms and need a little Help. In my first Form I am import data from local sql database into datagridvdiew. Data is about Client Money Transfers. Now I need to make a Filter for my DGV, for example display all Client datas wich money transfers are more than 1500$. Such querys can be more than one So am I Calling another Form on buttonClick to enter all Filter parameters. After enterying parameters on ButtonClick I need to filter data in DGV which is in first Form. But I donn't know how to change DGV from another Form. I was trying to call form1 by this way:
Form form1 = new Form(); But I can not still reach DGV. Who can help me with this ?

推荐答案

。这样的查询可以不止一个所以我在buttonClick上调用另一个表单来输入所有过滤器参数。在ButtonClick上输入参数后,我需要过滤第一个Form中的DGV中的数据。但我不知道如何从另一个表格改变DGV。我试图通过这种方式调用form1:

Form form1 = new Form();但我还是不能达到DGV。谁可以帮我这个?
. Such querys can be more than one So am I Calling another Form on buttonClick to enter all Filter parameters. After enterying parameters on ButtonClick I need to filter data in DGV which is in first Form. But I donn't know how to change DGV from another Form. I was trying to call form1 by this way:
Form form1 = new Form(); But I can not still reach DGV. Who can help me with this ?


使用以下参数创建一个复选框:



Create a checkbox with the following parameter:

private void chkBox_CheckedChanged(object sender, EventArgs e)
        {
            
            MySqlDataAdapter sda = new MySqlDataAdapter();
            MySqlConnection Con = new MySqlConnection("server=localhost;user id=root; password = 12345; persistsecurityinfo=True;database=YOURDB");
            MySqlCommand Command = new MySqlCommand("SELECT COLUMN from TABLE WHERE COLUMN;", Con);
            DataTable dt = new DataTable();
            sda.SelectCommand = Command;
            sda.Fill(dt);
            DgvGerirEmp.DataSource = dt;
            if (chkBox.Checked == true)
            {
                MySqlCommand Command = new MySqlCommand("SELECT COLUMN from TABLE WHERE COLUMN <=1500;", Con);

            }
            else
            {
                MySqlCommand Command = new MySqlCommand("SELECT COLUMN from TABLE WHERE COLUMN >=1499;", Con);
                GerirEmpArq.Show();
                GerirEmpDesArq.Hide();
                
            }
            

        }





我没有测试过它应该工作正常,我已经在一些项目中自己使用它,按你的意愿使用它。



I didn't tested it but it should work fine, i've used it myself on some projects, use it as you wish.


这篇关于如何从另一个表单中过滤datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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