I've been looking for a way. To Edit, update and delete my data using a contextmenustrip.
Basically what I want is for my contextmenustrip to be able to interact with Datagridview, the problem is whenever I set the code for click event. it shows an error, I am still new in c# so I am probably not figuring something out. this is my code.
private void DgAddnew_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show("You can now Edit this data, Choose Update Button To populate, Thank you!", "Edit Data,", MessageBoxButtons.OK, MessageBoxIcon.Information);
int index = e.RowIndex;// get the Row Index
DataGridViewRow selectedRow = dgAddnew.Rows[index];
txtNAME.Text = selectedRow.Cells[1].Value.ToString();
txtADDRESS.Text = selectedRow.Cells[2].Value.ToString();
txtCELLPHONE.Text = selectedRow.Cells[3].Value.ToString();
txtCODE.Text = selectedRow.Cells[4].Value.ToString();
cmbTYPE.Text = selectedRow.Cells[5].Value.ToString();
cmbCOLOR.Text = selectedRow.Cells[6].Value.ToString();
cmbHEELS.Text = selectedRow.Cells[7].Value.ToString();
cmbPAYMENT.Text = selectedRow.Cells[8].Value.ToString();
cmbPRICE.Text = selectedRow.Cells[9].Value.ToString();
cmbRESERVE.Text = selectedRow.Cells[10].Value.ToString();
cmbBONDFEE.Text = selectedRow.Cells[11].Value.ToString();
dpDATEOUT.Text = selectedRow.Cells[12].Value.ToString();
dpDATERETURN.Text = selectedRow.Cells[13].Value.ToString();
}
this work in datagridview. but when i add it on contextmenu all this item doesn't populate, and i get a row index error.
private void EDITToolStripMenuItem_Click_1(object sender, EventArgs e)
{
MessageBox.Show("You can now Edit this data, Choose Update Button To populate, Thank you!", "Edit Data,", MessageBoxButtons.OK, MessageBoxIcon.Information);
int index = e.RowIndex;// get the Row Index
DataGridViewRow selectedRow = dgAddnew.Rows[index];
txtNAME.Text = selectedRow.Cells[1].Value.ToString();
txtADDRESS.Text = selectedRow.Cells[2].Value.ToString();
txtCELLPHONE.Text = selectedRow.Cells[3].Value.ToString();
txtCODE.Text = selectedRow.Cells[4].Value.ToString();
cmbTYPE.Text = selectedRow.Cells[5].Value.ToString();
cmbCOLOR.Text = selectedRow.Cells[6].Value.ToString();
cmbHEELS.Text = selectedRow.Cells[7].Value.ToString();
cmbPAYMENT.Text = selectedRow.Cells[8].Value.ToString();
cmbPRICE.Text = selectedRow.Cells[9].Value.ToString();
cmbRESERVE.Text = selectedRow.Cells[10].Value.ToString();
cmbBONDFEE.Text = selectedRow.Cells[11].Value.ToString();
dpDATEOUT.Text = selectedRow.Cells[12].Value.ToString();
dpDATERETURN.Text = selectedRow.Cells[13].Value.ToString();
}
the part it has "e.RowIndex" Gives error. Is there A way I can declare a global declaration or store a rowIndex to a container and be able to interact with the contextmenustrip,??
I've been figuring it for days and it still doesn't work. Its my 12days of learning c# as my first language and it frustrates me that I still suck so bad. pls help me. Thanks.