Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following line of codes in the system.
VB
Private Sub DataGridView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick

rcdraw = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCell.ColumnIndex, DataGridView1.CurrentCell.RowIndex, False)
       If DataGridView1.CurrentCell.Selected = True Then
           selection = True
       Else
           selection = False
       End If
   End Sub

Private Sub DataGridView1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles DataGridView1.Paint
     
        If selection = True Then
            DrawEllipseRectangle(e)
        Else
         
        End If
    End Sub

    Private Sub DrawEllipseRectangle(ByVal e As PaintEventArgs)
  
        Dim redPen As New Pen(Color.Red, 3)
        Dim rect As New Rectangle(0, 0, 200, 100)
        e.Graphics.DrawEllipse(redPen, rcdraw)
    End Sub

My intention is to whenever I click on the cell draw an ellipse on the selected cell.

The problem is it draws ellipse only after I click on another cell. It doesn't draw the ellipse whenever I click the cell.

Any ideas please help
Posted
Updated 28-Aug-12 20:38pm
v2

1 solution

Call Invalidate for the DataGridView in your click event - Paint is only called when it is needed, i.e. after an Invalidate or when it is "uncovered".
 
Share this answer
 
Comments
Reji Ab 29-Aug-12 4:17am    
Thank you, that works

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900