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:
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?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
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.




Reply With Quote