nice.atma nice.atma - 1 month ago 8
Vb.net Question

Popup on Selected Cell

I have datagridview with a panel that pops-up when a cell is selected using this code

Private Sub dgvPurchase_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles dgvPurchase.EditingControlShowing
pnlItem.Location = New Point(314, 234)
If pnlItem.Visible Then
pnlItem.Visible = False
Else
pnlItem.Visible = True
End If

End Sub


The problem is the panel pops-out whichever cell I click. I want the panel to be visible only when I click a cell of a particular column in the row not on all cells in the row.

Answer

Check the CurrentCell.RowIndex before doing anything...

 If dgvPurchase.CurrentCell.RowIndex = YOURROWINDEX Then
   pnlItem.Location = New Point(314, 234) 
   If pnlItem.Visible Then
      pnlItem.Visible = False
   Else
      pnlItem.Visible = True
   End If
 End If

Note: This is just one way, there are a few other ways as well, but this should help you.

Also I noticed you haven't accepted any solutions given to you that helped. On that note, SO is for helping others fix problems. If an answer has helped please be kind and reward them back by checking the checkmark and voting.

EDIT

Per your comments you want a specific column not row...

      If dgvPurchase.CurrentCell.ColumnIndex = YOURCOLUMNINDEX

This event will only happen if it's the column you want.

Comments