Click here to Skip to main content
16,019,957 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 ?
Posted
Comments
Alex M.H. 20-Jan-16 10:11am    
You cannot directly access a class in the calling form from the outside easily, imagine what will go on in your "mainform"-class after you call your "inputform"-class - you never know. The "back-call" that you're planing to implement is not threadsafe.

I think there are three ways to solve the situation
1. scope to threading (slightly pushing it)
2. use events/messages (my favorit, not very difficult to understand)
3. do it in one form (hide/show input area, resize the form for your needs - the dirty way)

C# in a nutshell (o'reilly) may help with the details

1 solution

Create a checkbox with the following parameter:

C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900