• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Datagrid Row-property

I´m using a Datagrid that has 8 columns. When the user clicks in a cell I would like to determine which row and column he clicked. This because if the user clicks in column 5 a window should appear otherwise should the row get highlighted (selected).

When I´m using the Col- and Row-properties of the Datagrid it is one step behind. For example: I click in column 4 and row 2, the col and row properties show the value -1. Next time I click column 5 and row 3, now the properties show the value 4 and 2 (as it should on the first click):

Therefore I have these questions:
1) How do I solve this matter and determining the right column and row?

2) How do I highlight a single row when the user clicks a cell?

1 Solution
TimCotteeHead of Software ServicesCommented:
This code should provide what you want.

Private Sub grdDataGrid_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    If grdDataGrid.Col = 4 Then
        MsgBox ("In Col 5")
        If grdDataGrid.SelBookmarks.Count > 0 Then
            For Each bmkBookmark In grdDataGrid.SelBookmarks
                bmkBookmark.Remove (0)
        End If
        grdDataGrid.SelBookmarks.Add (grdDataGrid.RowBookmark(grdDataGrid.Row))
    End If
End Sub
polksolkAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now