Visual c# Read DataGridView data and show in PictureBox

im sorry fot being a newbie on this language. Here's my simple situation.

I have a DataGrid where i put my inventory items in this way:

 public void UpdateInventoryListUI()
    {
        dGridInvetory.RowHeadersVisible = false;

        dGridInvetory.ColumnCount = 2;
        dGridInvetory.Columns[0].Name = "Name";
        dGridInvetory.Columns[0].Width = 112;
        dGridInvetory.Columns[1].Name = "Quantity";

        dGridInvetory.Rows.Clear();


        foreach (InventoryItem inventoryItem in mainForm1._player.Inventory)
        {
            if (inventoryItem.Quantity > 0)
            {


                dGridInventory.Rows.Add(new[] { inventoryItem.Details.Name, oggettoInventory.Quantity.ToString() });
            }

        }            
    }

Ok it works fine and show me my items. Now i want to create an event that when i select with mouse the Row (entire Row - so the name and the quantity) it shows me in the picture box the image of that item. I need to know how to read the STRING like below:

    private void dGridInventory_MouseClick(object sender, MouseEventArgs e)
    {
          if(// the string "Name" on row is == "Mask_DPS"){
          picBoxMask.Image = Properties.Resources.MASK_DPS;
          labelInfo.Text = "This is a dps Mask!";
    }
          if((// the string "Name" on row is == "Mask_TANK"){
          picBoxMask.Image = Properties.Resources.MASK_TANK;
          labelInfo.Text = "This is a tank mask!;

          //...and so on!
    }

Can you help me please? Just wanna click on the Row and compare the string in the Row. If is the same then show me the image in my picture box.

Thank all and sry for my bad english.

Answers


You are not using the best event for what you want to accomplish. Try using the SelectionChanged event instead:

void dGridInventory_SelectionChanged(object sender, EventArgs e) {
  if (dGridInventory.CurrentRow != null) {
    if (dGridInventory.CurrentRow.Cells["Name"].Value.ToString() == "Mask_DPS") {
      // etc...
    }
  }
}

Make sure the event is properly subscribed to the DataGridView control.


Need Your Help

Controlling component data across multiple routes

ember.js

I have a mapping app that has a full-screen map with a sidebar for information. This app has two routes: