Reputation: 179
i have a DataGridView
in my program that has a DataGridViewButtonColumn
.
When a user clicks on that button, it shows more detail on another panel.
I am having trouble trying to do the following:
Click the "send" button on an ordering screen, that will send the order to the database, and the DataGridView
will automatically update, but the user still will need to click on the corresponding column button on the row to view more detail.
What i want to do is that when the user clicks send, it will automatically find the row that corresponds to the orderID, and automatically click that button.
this is what i have:
foreach(DataGridViewRow row in OutOrderListGridView.Rows){
string compareID = row.Cells[0].Value.ToString();
if (compareID == OrderID)
{
row.Cells[10].Selected = true; <-- here i want to performClick() on the columnbutton(cell[10]) on the specific row.
}
}
Thank you.
Upvotes: 0
Views: 1460
Reputation: 183
I am not 100% sure i quite understand what you are after, but if i am correct you want to do the following provided the CellClick event is handling whatever you are trying to ultimately achieve.
Instead of 'performing' the click ( PerformClick()
) as such you can raise the event manually with known values... This should work for you but is slightly untested in your particular application given unknown variables. Code below also had to be slightly reworked to suit.
for (int i = 0; i < OutOrderListGridView.RowCount; i++)
{
if (OutOrderListGridView[0, i].Value.ToString() == OrderID)
{
OutOrderListGridView_CellClick(OutOrderListGridView, new DataGridViewCellEventArgs(10, i));
break;
}
}
The foreach
loop had to be changed to a for
loop in order to make use of the current index (position of the loop) that a foreach
loop does not provide.
The string comparison did not need to be two stepped so was condensed accordingly.
I have also added a break
to the loop as i would think that once you found your match, it would be pointless to iterate through the remaining rows.
Upvotes: 1