DataGridView records actions
Hello,
How can i make a dataGridView to work programmatically when the user leaves the row? (add,delete,save/update records).
Thank you in advance.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Aug 25, 2009, 3:22 PM
Here is How you will check weather it is was new row or not . :)
private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
{
int index = e.RowIndex;
if (dataGridView1.Rows[index].IsNewRow == false)
{
// string PrimaryKey = dataGridView1.Rows[index].Cells[0].Value.ToString();
//string Column1 = dataGridView1.Rows[index].Cells[2].Value.ToString();
//string Column2 = dataGridView1.Rows[index].Cells[2].Value.ToString();
// string Column3 = dataGridView1.Rows[index].Cells[2].Value.ToString();
}
else
{
// Code For Inserting if it was new
MessageBox.Show("It Was New Line");
}
}
DealyPosted Aug 27, 2009, 4:29 AM
DealyPosted Aug 25, 2009, 1:16 PM
Kirtan PatelPosted Aug 25, 2009, 11:17 AM
you can do it with RowLeave Event of DataGridView
private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
{
//Get the Rowindex
int index = e.RowIndex;
//get Current Values of Columns From Row to Write in Database
string PrimaryKey = dataGridView1.Rows[index].Cells[0].Value.ToString();
string Column1 = dataGridView1.Rows[index].Cells[1].Value.ToString();
string Column2 = dataGridView1.Rows[index].Cells[2].Value.ToString();
string Column3 = dataGridView1.Rows[index].Cells[3].Value.ToString();
//Sql Programming For Updating Record in Database Here From Above Values
// Execute Query Like
// update tablename set x=value ,y =value where primarykey = Primarykey
}