dear all ,
i have small table student(id,name,last_name,address) and small screeen with datagridview iam trying to make insert and update
i want to add record in datagrid and then user enter data in that record
this my code , i do not know if it's possible or not
private void button1_Click(object sender, EventArgs e)
{
DataRow dr = dt.NewRow();
dr["student_id"] = Convert.ToInt32(textBox1.Text);
dr["student_name"] = textBox2.Text;
dr["student_last_name"] = textBox3.Text;
dr["address"] = textBox4.Text;
dt.Rows.Add(dr);
obj.addstudent(Convert.ToInt32(dr["student_id"].ToString()), dr["student_name"].ToString(), dr["student_last_name"].ToString(), dr["address"].ToString());
dataGridView1.DataSource = dt;
}
other thing update i want event firing after all cells in the same row updated not firing the event for each cell separetly like what happen in asp (rowupdating) this is my code :
int x, y;
private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
x = dataGridView1.CurrentCellAddress.X;
y = dataGridView1.CurrentCellAddress.Y;
}
private void dataGridView1_CancelRowEdit(object sender, QuestionEventArgs e)
{
x = -1;
y = -1;
}
int id;
string name, lname, add;
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
string s = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
id=Convert.ToInt32( dataGridView1 .Rows[e.RowIndex ].Cells[0].Value.ToString());
name=dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
lname = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
add = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
}
private void btnupdate_Click(object sender, EventArgs e)
{
int done = obj.updat(id,name,lname,add);
}
thanks and regards