Getting row and column numbers when right clicking on a cell

Originally Posted 10 March 2015, 10:37 am EST

  • Originally Posted 10 March 2015, 10:37 am EST

    I have started to use VSFlexGrid for ActiveX. I am programming in C++ and MFC.

    When the user clicks on a cell with the right mouse button on a cell, I want to get the row and column numbers of the cell.

    Is there an event that I can use to get the row and column numbers?

    With the event MouseDownVsflexgridl(short Button, short Shift, float X, float Y) I can get the x and y coordinates, but how can I get the row and column numbers of the cell?

    Do I have to calculate it?
  • Reply


    On the BeforeMouseDown event of the grid -> check for the mouse button that has been pressed and then use the MouseRow and MouseCol properties of the VsFlexgrid object to retreive the row and column indices when the cell the is right clicked.

    Here is the corressponding VB6 code for the same :

    Private Sub VSFlexGrid1_BeforeMouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single, Cancel As Boolean)

    If Button = MouseButtonConstants.vbRightButton Then

    MsgBox "Row : " & VSFlexGrid1.MouseRow & ", Column : " & VSFlexGrid1.MouseCol

    End If

    End Sub

    (I am having a very limited knowledge of the VC6 but the control should work in the same way as it does in VB6)

    Let me know if you face any issues.

  • Reply

    I have written the following code in C++ :

    void CMyTestView::BeforeMouseDownVsflexgridl1(short Button, short Shift, float X, float Y, BOOL* Cancel)

    long col = m_Grid.get_MouseCol();
    long row = m_Grid.get_MouseRow();

    if (Button == 2) // right mouse button



    It does not work as I want to. No matter which cell I click on, the variable col will have the value 2 and row will have the value -1.
  • Marked as Answer



    The following code works correctly for me :
    void CVsFlex_BeforeEditDlg::OnBeforeMouseDownVsflexgridl1(short Button, short Shift, float X, float Y, BOOL FAR* Cancel) 
    // TODO: Add your control notification handler code here

    long row = m_Grid.GetMouseRow();
    long col = m_Grid.GetMouseCol();

    char row_szBuffer[10];
    char col_szBuffer[10];

    _stprintf(row_szBuffer, _T("%i"), row);
    _stprintf(col_szBuffer, _T("%i"), col);

    if (Button == 2) // right mouse button
    MessageBox(row_szBuffer , _T("wat"), MB_OK);
    MessageBox(col_szBuffer , _T("wat"), MB_OK);

    Please refer to the attached gif image depicting the behavior at my end.

    I would suggest you to please test the case once with the latest VsFlexGrid Build : available at :

    Hope this helps.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels