如何在没有关闭表单2或显示表单1的情况下从另一个表单刷新数据网格

时间:2017-08-20 13:10:41

标签: c# search datagrid

我有2个表单(form1和表单2) form1有一个datagridview,form2有一个文本框,我怎么能刷新form1并搜索txtbox而不重载或show form1,我的意思是form2是一个搜索框,我怎么能控制form2中form1的datagrid?

private void datagrid_users_KeyPress(object sender, KeyPressEventArgs e)
    {


        win_searchuser baz = new win_searchuser() ;
        baz.searchname = datagrid_users.Columns[datagrid_users.CurrentCell.ColumnIndex].HeaderText;
        baz.columnname = datagrid_users.Columns[datagrid_users.CurrentCell.ColumnIndex].Name;

        baz.ShowDialog();

    }

窗口2

private void txt_name_TextChanged_1(object sender, EventArgs e)
    {
        var query = data.Database.SqlQuery<vw_users>("Select * from vw_users where "+columnname+" like '%"+txt_name.Text+"%'");
        var u = query.ToList();
        dataGridView1.DataSource = u;
        users tt = new users();

         tt.datagrid_users.DataSource = this.dataGridView1.DataSource;




    }