So its a bit of a long question I am running into a severe problem where I have a windows form C# application that is a bicycle inventory management system for one of my college classes. I have figured out how to remove a currently selected 'Part' from the datagridview by building the code inside of a button_click event, but that is for that specific form and my class wants me to build a specific deletePart bool method taking a Part parameter that includes ID, name, price, inStock, min, and max.I have not been able to find a way to transfer the code from the button_click event to the deletePart method and would like some assistance.
public static bool deletePart(Part deletedPart)
{
MainScreen mainScreen = new MainScreen();
bool isDeleted = false;
if (MessageBox.Show("Are you sure you want to remove this part?", "Remove Part", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
isDeleted = true;
}
if (isDeleted == true)
{
mainScreen.PartsGridView.Rows.RemoveAt(mainScreen.PartsGridView.CurrentRow.Index);
}
return isDeleted;
}
This is all I have inside my button_click Event
private void DeleteBtn_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to remove this part?", "Remove Part", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
PartsGridView.Rows.RemoveAt(PartsGridView.CurrentRow.Index);
}
}
Any advice on how to build the deletePart method would be helpful I am so lost.