Results 1 to 5 of 5

Thread: [RESOLVED] Put ListBox over top cell in DataGridView column

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    85

    Resolved [RESOLVED] Put ListBox over top cell in DataGridView column

    I've got this working but there's something I don't understand about it. I have a DataGridView and a listbox. I want to position the listbox to be the same location as the topmost visible cell in the column the mouse is in. The end result will be that a context menu will be provided to show the user the distinct values in that column which is why I want the listbox to show over the column that it's displaying data for, just below the header cell. I'm testing right now using the CellMouseEnter event and the following code is working:
    Code:
    Private Sub dgvItems_CellMouseEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvItems.CellMouseEnter
    	If e.ColumnIndex >= 0 Then
    		Dim r As System.Drawing.Rectangle = dgvItems.GetCellDisplayRectangle(e.ColumnIndex, 0, True)
    		lstDistinctValues.Location = New System.Drawing.Point(r.Left + 9, dgvItems.Top + 69)
    		lstDistinctValues.Visible = True
    	End If
    End Sub
    But notice the offsets that I had to use to get the positioning just right. That's my question - why is using the location of the cell putting my textbox so far off from where I want it?

    Thanks!

    Edit: if I use the rectangle's Y position as the top of the ListBox, the ListBox ends up completely outside the DataGridView which is why I'm using the DataGridView's Y position.
    Last edited by BrainPain; May 26th, 2011 at 08:26 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width