C# – get value from datagrid cell in C#

cdatagrid

How do I get the info from a certain cell in a data grid? I want an event to happen when a person clicks the button in the 7th column, but the event depends on the value in the first column. here's what i have, but nothing is happening.

if (InventoryDataGridView.CurrentCell.ColumnIndex == 7)
            {

                if(InventoryDataGridView[0,0].Equals("Books"))
                {
                    Books open = new Books();
                    open.Show();
                }

        }

Nothing happens though

Best Answer

InventoryDataGridView[0,0]

only refers to the DataGridViewCell. That class has a Value property which contains the value of the cell.

so that line should look like this:

if(InventoryDataGridView[0,0].Value.Equals("Books"))
{
  //
}