I have datagridview in form1. How can I access datagridview from form2.
private void button1_Click(object sender, EventArgs e)
{
string sql1 = "insert into Car (plate, color, [year], model) values ('"+tplate.Text+"','"+tcolor.Text+"',"+tyear.Text+",'"+tmodel.Text+"')";
string sql2 = "select * from Car";
try
{
int res = CarDatabase.executeOthers(sql1);
if(res >0){
DataTable dt = CarDatabase.executeSelect(sql2);
mainframe.Dgv.DataSource = dt;
MessageBox.Show("New Car is added");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
here mainframe.Dgv is in the first form
but I cannot access like that Form1.dataGridView why :S
In Form2:
In Form1:
In Form2 access its own Dgv propety.