if i right-click on a flexgrid i want to display a menu under the cursor.
How to fix this
Printable View
if i right-click on a flexgrid i want to display a menu under the cursor.
How to fix this
here u go, i created this in like 1 min...
thanks
And how to add menu items (in the right click menu) dynamically in the form in which the grid is?
Do u mean u want to add more menu's at runtime ?? You will have to use the API for that.
yes
now there is only flexgrid popup in the menu.
But i want to add more items like this on it.
If i have to use the API. could you please tell me how to use it.
thanks in advance
uhh just add them thru mnu editor in the frmpopup form.
is there no way to do it a design time
Ok if you add a menu thru the menueditor that is at designtime. If you want to add menu items after your program is compiled then this is adding at runtime. If you open the frmpopup form and goto tools/menueditor, u will see the popup items. u may add more popups there. if u want to add to it after your program is compiled, search on the forums theres plenty of examples
next problem
when i right click on a row and another row was selected before i'm rightclicking on the row that was selected and not on the one where my cursor was
your gonna have to retype that last message, i don't understand that at ALL, LOL
So when i right click on the 3 th row
and the 1st row was selected
and i ask for the row and col value.
then i get row 1 instead of the 3 th
ooh ok i get u now. What you can do is use the Mouse_Event API to send a mouseclick to the flexgrid before popping up the menu at point where the right click event happened then right after that put the code to popup the menu. Try this example below.
Add The Below To Your Declarations In Your Form
VB Code:
Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) Private Declare Function SetCursorPos Lib "user32.dll" (ByVal X As Long, ByVal Y As Long) As Long Private Const MOUSEEVENTF_LEFTDOWN = &H2 Private Const MOUSEEVENTF_LEFTUP = &H4 Private Const MOUSEEVENTF_RIGHTDOWN = &H8 Private Const MOUSEEVENTF_RIGHTUP = &H10
then delete whatever code you have in the Mouse_Down even of the flexgrid and add this bit of code to the Mouse_Down event of the flexgrid.
[Highlight=VB]
If Button = 2 Then
DoEvents
Call mouse_event(MOUSEEVENTF_LEFTDOWN, X, Y, 0, 0)
Call mouse_event(MOUSEEVENTF_LEFTUP, X, Y, 0, 0)
DoEvents
frmpopup.PopupMenu frmpopup.mnupopup
End If
[Highlight=VB]
there you go, all this does is sends a left click before the menu pops up. I don't know if this is the right way to do it, but it works.
There is an easier way, I found after a lot of searching...
Why they can't just use .RowContaining and .ColContaining like all the other grids is beyond me.VB Code:
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) If Button = vbRightButton Then MSFlexGrid1.Row = MSFlexGrid1.MouseRow MSFlexGrid1.Col = MSFlexGrid1.MouseCol ' run whatever code you have End If End Sub
Tom