Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate Datagridview From Another Form
    text
    copied!<p>First I should say i saw this link : </p> <p><a href="https://stackoverflow.com/questions/2395624/how-to-refresh-datagridview-when-closing-child-form">How to refresh datagridview when closing child form?</a></p> <p>And i did like this: (i have datagridview in Form1) <strong>Form1:</strong></p> <pre><code> public void FillDataGridView(DataTable dt1) { bindingSource1.DataSource = dt1; bindingSource1.ResetBindings(false); dataGridView1.DataSource = bindingSource1; //here i checked number of rows of dt1 and it shows the correct value } </code></pre> <p><strong>Form2:</strong></p> <pre><code> SqlConnection cnn = new SqlConnection(@"My connection string"); private Form1 Handled_frm1; public Form2(Form1 frm1) { InitializeComponent(); Handled_frm1 = frm1; } private void textbox1_TextChanged(object sender, EventArgs e) { dt.Clear(); using (SqlCommand cmd =cnn.CreateCommand()) { if (cnn.State == ConnectionState.Closed) { cnn.Open(); } cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = cnn; cmd.CommandText = "spSearchCustomerByName"; SqlParameter inparam1 = cmd.Parameters.AddWithValue("@name", textbox1.Text); inparam1.Direction = ParameterDirection.Input; dap.SelectCommand = cmd; dap.Fill(dt); Handled_frm1.FillDataGridView(dt); } </code></pre> <p>But the value Of Datagridview does not change!</p> <p><strong>Edited:</strong></p> <p>I wanted to test that if i can clear datagrid view or not,so i changed FillDataGridView like this :</p> <pre><code> public void FillDataGridView(DataTable dt1) { dt.Clear(); dataGridView1.Columns.Clear(); dataGridView1.DataSource = null; dataGridView1.Refresh(); } </code></pre> <p>but it does not clear datagridview1!!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload