So, I am trying to use an Event from C# into the TextBox which could be able to after selecting something from a DataGridView it will insert that columns values in the TextBox and then detailed the info from what it is in the TextBox.
I don't want to use TextChanged
What could I do to after the value shows on TextBox it will go to DataGridView?
What I have tried:
public bool ValidateText()
{
bool Isvalidated = false;
try
{
SqlConnection con = new SqlConnection(cs.DBConnP);
con.Open();
adp = new SqlDataAdapter();
adp.SelectCommand = new SqlCommand(@"", con);
ds = new DataSet("ds");
adp.Fill(ds);
dtable = ds.Tables[0];
adp.Fill(ds, "CargaCab");
dataGridView1.DataSource = ds.Tables["CargaCab"].DefaultView;
foreach (DataRow row in dt.Rows)
{
int n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = row[0].ToString();
dataGridView1.Rows[n].Cells[1].Value = row[1].ToString();
dataGridView1.Rows[n].Cells[2].Value = row[2].ToString();
dataGridView1.Rows[n].Cells[3].Value = row[3].ToString();
}
dataGridView1.Columns[0].ReadOnly = true;
dataGridView1.Columns[1].ReadOnly = true;
dataGridView1.Columns[2].ReadOnly = true;
dataGridView1.Columns[3].ReadOnly = false;
con.Close();
}
catch (Exception ex)
{
MessageBox.Show("Erro\nDetalhes: " + ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
Isvalidated = false;
}
return Isvalidated;
}
private void txtCarga_Validating(object sender, CancelEventArgs e)
{
ValidateText();
int LinhasAfetadas = 0;
LinhasAfetadas = dataGridView1.RowCount;
label1.Text = "Número de registos: " + LinhasAfetadas;
}