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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 25, 2009, 11:22 AM EDT
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");
}
}
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 25, 2009, 7:17 AM EDT
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
}
DealyRank #9,518 · 205 reputationPosted Aug 25, 2009, 9:16 AM EDT
DealyRank #9,518 · 205 reputationPosted Aug 27, 2009, 12:29 AM EDT