title: set Tag property datagridview C#
body: <p>I'm creating  a datagridview in WinForms. Each cell in the datagridview is either a textboxcell or datagridview image cell. I'm firing a cellMouseDownEent( object sender, DataGridViewCellMouseEventArgs e). If the sected cell is a image cell I perform task1 and if it is textboxcell  I perform task2. I'm not getting how to find out whether the current cell is image cell or text box cell. I tried setting tag property of image cell to 0 and textboxcell cell to 1 to identify which is being clicked, but no luck. Any advice is aapreciated.</p>
  
  <p>Thanks,</p>
  
  <pre><code>I'm adding my code here:
  Ignore if a column or row header is clicked
                  if (e.RowIndex != -1 &amp;&amp; e.ColumnIndex != -1)
                  {
                      if (e.Button == MouseButtons.Right)
                      {
                          DataGridViewCell clickedCell = (sender as DataGridView).Rows[e.RowIndex].Cells[e.ColumnIndex];
  
                          // Here you can do whatever you want with the cell
                          this.dgvAddFilters.CurrentCell = clickedCell;  // Select the clicked cell, for instance
  
  
                          // Get mouse position relative to the vehicles grid
                          var relativeMousePosition = dgvAddFilters.PointToClient(Cursor.Position);
                          if (clickedCell.Tag.ToString()==null)
                          {
                              return;
                          }
                          else if (imageCell == null) return;
                          else if (e.ColumnIndex == 0 &amp;&amp; e.RowIndex == 0)
                          {
                              if ((dgvAddFilters[e.ColumnIndex, e.RowIndex + 2].Value == null))
                              // (dgvAddFilters[e.ColumnIndex + 2, e.RowIndex].Value == null))
                              {
                                  dgvAddFilters.ContextMenuStrip = contMenuOr;
                                  this.contMenuOr.Show(dgvAddFilters, relativeMousePosition);
                              }
                              else return;
                          }
                          else if ((e.ColumnIndex == 0)
                             &amp;&amp; (e.RowIndex &gt; 0)
                             &amp;&amp; (dgvAddFilters[e.ColumnIndex + 2, e.RowIndex].Value == null)
                             &amp;&amp; (dgvAddFilters[e.ColumnIndex, e.RowIndex + 2].Value == null)
                             &amp;&amp; (dgvAddFilters[e.ColumnIndex, e.RowIndex].Value != null))
                          {
                              dgvAddFilters.ContextMenuStrip = contMenuFilterMenu;
                              this.contMenuFilterMenu.Show(dgvAddFilters, relativeMousePosition);
                          }
                          else if ((e.ColumnIndex == 0)
                              &amp;&amp; (e.RowIndex &gt; 0)
                              &amp;&amp; (dgvAddFilters[e.ColumnIndex, e.RowIndex + 2].Value == null)
                              &amp;&amp; (dgvAddFilters[e.ColumnIndex + 2, e.RowIndex].Value != null)
                              &amp;&amp; (dgvAddFilters[e.ColumnIndex, e.RowIndex].Value != null))
                          {
                              dgvAddFilters.ContextMenuStrip = contMenuOrEditDelete;
                              this.contMenuOrEditDelete.Show(dgvAddFilters, relativeMousePosition);
                          }
                          else if ((e.ColumnIndex == 0)
                             &amp;&amp; (e.RowIndex &gt; 0)
                             &amp;&amp; (dgvAddFilters[e.ColumnIndex + 2, e.RowIndex].Value == null)
                             &amp;&amp; (dgvAddFilters[e.ColumnIndex, e.RowIndex + 2].Value != null)
                             &amp;&amp; (dgvAddFilters[e.ColumnIndex, e.RowIndex].Value != null))
                          {
                              dgvAddFilters.ContextMenuStrip = contMenuAndDeleteEditMenu;
                              this.contMenuAndDeleteEditMenu.Show(dgvAddFilters, relativeMousePosition);
                          }
                          else if ((dgvAddFilters[e.ColumnIndex, (e.RowIndex + 2)] != null)
                              &amp;&amp; (dgvAddFilters[(e.ColumnIndex + 2), e.RowIndex].Value != null)
                               &amp;&amp; (dgvAddFilters[e.ColumnIndex, e.RowIndex].Value != null))
                          {
                              dgvAddFilters.ContextMenuStrip = contmenuDeletEdit;
                              this.contmenuDeletEdit.Show(dgvAddFilters, relativeMousePosition);
                          }
                          else if ((dgvAddFilters[e.ColumnIndex, (e.RowIndex + 2)] != null)
                              &amp;&amp; (dgvAddFilters[e.ColumnIndex, e.RowIndex].Value != null))
                          {
                              dgvAddFilters.ContextMenuStrip = contMenuAndDeleteEditMenu;
                              this.contMenuAndDeleteEditMenu.Show(dgvAddFilters, relativeMousePosition);
                          }
                          else
                          {
                              return;
                      }
  </code></pre>