Passing component data to a new function?
Newb here, but I cannot find an answer. I have a form with a tab control with four tabs and a datagridview of four different tables on each tab. I would like to streamline the code for deleting a line in the grids. Here is the code I have for one of the grids, it is the same on all four grids for each of the tables:
private void dataGridViewVendors_CellClick(object sender, DataGridViewCellEventArgs e)
{
bool NewRowSelected = true;
int GrdRow = this.dataGridViewVendors.RowCount - 1;
if (GrdRow == e.RowIndex)
{
NewRowSelected = false;
}
if (e.ColumnIndex == 0 && NewRowSelected)
{
DialogResult response = MessageBox.Show("Do you want to delete this record?", "Click Delete Record?",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
if (response == DialogResult.Yes)
{
String strNum2Delete = this.dataGridViewVendors[1, e.RowIndex].Value.ToString();
this.dataGridViewVendors.Rows.RemoveAt(e.RowIndex);
this.vendorsTableAdapter.DeleteQuery(strNum2Delete);
this.vendorsTableAdapter.Fill(this.pSWFixedAssetsDataSet.Vendors);
this.Refresh();
}
}
}
What I would like to have is something like this:
private void dataGridViewVendors_CellClick(object sender, DataGridViewCellEventArgs e)
{
GridDelete(dataGridViewVendors, vendorsTableAdapter, Vendors, e.RowIndex, e.ColumnIndex);
}
private void GridDelete(string GRIDNAME, string TABLEADAPT, string TABLE, int ROWIDX, int COLIDX)
{
bool NewRowSelected = true;
int GrdRow = this.GRIDNAME.RowCount -1;
if (GrdRow == ROWIDX)
{
NewRowSelected = false;
}
if (COLIDX == 0 && NewRowSelected)
{
DialogResult response = MessageBox.Show("Do you want to delete this record?", "Click Delete Record?",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
if (response == DialogResult.Yes)
{
String strName2Delete = this.GRIDNAME[1, ROWIDX].Value.ToString();
this.GRIDNAME.Rows.RemoveAt(ROWIDX);
this.TABLEADAPT.DeleteQuery(strName2Delete);
this.TABLEADAPT.Fill(this.pSWFixedAssetsDataSet.TABLE);
this.Refresh();
}
}
}
Thanks for any input.
Del