Can't combobox properly placed over datagrid cell

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
T

Terry Olsen

Here's my code:

Private Sub dgServerList_CurrentCellChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles dgServerList.CurrentCellChanged
If dgServerList.CurrentCell.ColumnNumber = 2 Then
Dim cellRect As Rectangle =
dgServerList.GetCurrentCellBounds()
cboMailList.SetBounds(cellRect.X, cellRect.Y,
cellRect.Width, cellRect.Height)
cboMailList.Show()
Else
cboMailList.Hide()
End If
End Sub

Problem: The combobox shows up above & left of the cell it should be
covering. Can anyone help? Thanks!
 
I could be wrong, I don't have a way to check right now, but doesn't the
GetCurrentCellBounds() return the coords in relation to the Datagrid. So
you would have to compensate for the offset of the datagrid. Just my
thought.

Chris
 
I figured it out...but ran into another problem...here's the code:

Private Sub RepaintComboBox()
Dim dg As Rectangle = dgServerList.GetCurrentCellBounds
Dim cb As Rectangle =
Me.RectangleToClient(dgServerList.RectangleToScreen(dg))
cboMailList.SetBounds(cb.X, cb.Y, cb.Width, cb.Height)
cboMailList.Show()
cboMailList.BringToFront()
End Sub

I added a call to this Sub in the DataGrid_Scroll event. But now when
the row that the combobox is in scrolls out of view, the ComboBox
continues to be painted over the rest of the form as if the row was
still visible. I can't seem to find a way to tell if a row in a
datagrid is visible or not. Can anyone help with this? Thanks!
 
I can't seem to find a way to tell if a row in a
datagrid is visible or not. Can anyone help with this? Thanks!

Hi Terry

Yep. Thats a bit of a curly one because it is not immediately obvious which event to register for
and that you can override the GridVScrolled method. However thats the event you want (assuming your
overriding the datagrid of course). NewValue property will give you the current verticsl value of
the scroll bar so you can do some basic arithmetic re: vert pos / row height = row etc.

It will also tell you the type of scroll event LargeInc/Small inc which could be helpful if you want
to decide whether there is any point in bothering to do a draw.
Note also that when setting the new value position this will only set the scroll position;it will
not update CurrentRow so you have to do another calc to sync these manually.

Protected Overrides Sub GridVScrolled(ByVal sender As Object, ByVal se As ScrollEventArgs)
Debug.WriteLine(se.NewValue)
Debug.WriteLine(se.Type.ToString())
End Sub

hth
Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top