This is a little confusing as you are referencing dataGridView
2 with the row and column numbers of where you have clicked in dataGridView
1. So assuming you really meant to do that (and that both grids contain the same text "sewagram express"...
In your click event (which is firing ok by the sound of it) you have declared
DataGridViewImageCell cell
but you want to compare this to a string ... this doesn't sound right to me so I changed that to
DataGridViewCell cell = (DataGridViewCell)dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex];
The next problem I hit is with
if (cell.Value=="sewagram express")<br />
which throws the warning
Quote:
Warning 1 Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string' C:\Users\C_2\AppData\Local\Temporary Projects\WindowsFormsApplication1\Form1.cs 34 17 WindowsFormsApplication1
so I changed that to
if (cell.Value.ToString() == "sewagram express")
and the code ran as expected. This last step wasn't strictly necessary because if you type
? cell.Value.GetType()
into the Immediate window you'll find that it is actually a string, but I really don't like leaving Warnings in my code.
I found all of this out by putting a breakpoint in the event and stepped through it taking careful note of what was appearing in my Errors, Output and Locals windows.