TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Del Woodcock
NA
67
7k
Passing component data to a new function?
Jul 14 2010 5:53 PM
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
Reply
Answers (
0
)
Place EXE file in Separate folder while Building the project
Word-style ruler with multiple tab stops