Forum Discussion

vthomeschoolmom's avatar
vthomeschoolmom
Super Contributor
14 years ago
Solved

click the cell of a grid

A helpful person here gave me a ClickCell routine that calculates where to click in a TrueDB Grid pro. I see in the help file a similar set of functions for clicking in the cell of a Janus Grid EX for .NET. I am using Janus Grid Ex 2000 for Visual Basic. The methods used in the .NET version are different than the 2000 version. Like any good programmer, I am lazy. :) I would rather use a wheel already created than create my own.



Has anyone already created this? Or do I need to actually... sigh... work for my income?



:)



Thanks



S
  • Figured it. If anyone needs this:



    Function getColByIndex(wGrid, strCol)

    ' Janus Grid Ex.



      Dim colCount, colId



      colCount = wGrid.Columns.Count



      For colId = 1 To colCount



        Set colObj = wGrid.Columns.Item(colId)



        If SameText(colObj.Caption, strCol) Then



          getColByIndex = colObj.Index



          Exit Function



        End If



      Next



      getColByIndex = -1



    End Function



    Sub ClickCellEx(grid, rowIndex, sColCaption, tShift)

    ' TruDBGridPro 8 to click within a cell

      Dim SplitNo, SplitCount



    ' Checks whether the grid contains the specified row

      If rowIndex < 1 Or rowIndex > grid.RowCount Then

        Log.Error "Row index " & rowIndex & " is out of bounds 1 ... " & grid.ApproxCount & "."

        Exit Sub

      End If



      ' Checks whether the grid contains the specified column

      'If Not aqObject.GetVarType(column) = 8 Then

      If Not aqObject.GetVarType(column) = varOleStr Then

        If column < 0 Or column > grid.Columns.Count Then

          Log.Error "Column index " & column & " is out of bounds 1 ... " & grid.Columns.Count & "."

          Exit Sub

       End If

      Else

        Err.Clear

        On Error Resume Next

          Set col = grid.Columns(column)

        If Err.Number <> 0 Then

          Log.Error Err.Description

          Exit Sub

        End If  

        

      End If



     

      lColIndex = getColByIndex(grid, sColCaption)

     

      ' Find the cell left and cell top, abnd cell height

      grid.Row = rowIndex

      grid.Col = lColIndex

      lLeft = grid.CellLeft()

      lTop = grid.CellTop()

      lHeight = grid.CellHeight()

        

     

      ' Calculates the horizontal coordinates of the cell (in VB twips)

      'xTwips = grid.Columns(column).Left + (grid.Columns(column).Width / 2)

      xTwips = lLeft+ (grid.Columns(lColIndex).Width / 2)

      ' Converts twips to pixels

      x = CLng(TwipsToPixelsX(xTwips))



      ' Calculates the vertical coordinates of the cell (in VB twips)

      'yTwips = grid.RowTop(rowIndexV) + grid.RowHeight / 2

      yTwips = lTop + lHeight / 2

      ' Converts twips to pixels

      y = CLng(TwipsToPixelsY(yTwips))



      ' Clicks the specified cell

      grid.Click x, y, tShift



    End Sub '' ClickCellEx

2 Replies

  • While we are discussing it, row header and column header clicks would be helpful too.
  • Figured it. If anyone needs this:



    Function getColByIndex(wGrid, strCol)

    ' Janus Grid Ex.



      Dim colCount, colId



      colCount = wGrid.Columns.Count



      For colId = 1 To colCount



        Set colObj = wGrid.Columns.Item(colId)



        If SameText(colObj.Caption, strCol) Then



          getColByIndex = colObj.Index



          Exit Function



        End If



      Next



      getColByIndex = -1



    End Function



    Sub ClickCellEx(grid, rowIndex, sColCaption, tShift)

    ' TruDBGridPro 8 to click within a cell

      Dim SplitNo, SplitCount



    ' Checks whether the grid contains the specified row

      If rowIndex < 1 Or rowIndex > grid.RowCount Then

        Log.Error "Row index " & rowIndex & " is out of bounds 1 ... " & grid.ApproxCount & "."

        Exit Sub

      End If



      ' Checks whether the grid contains the specified column

      'If Not aqObject.GetVarType(column) = 8 Then

      If Not aqObject.GetVarType(column) = varOleStr Then

        If column < 0 Or column > grid.Columns.Count Then

          Log.Error "Column index " & column & " is out of bounds 1 ... " & grid.Columns.Count & "."

          Exit Sub

       End If

      Else

        Err.Clear

        On Error Resume Next

          Set col = grid.Columns(column)

        If Err.Number <> 0 Then

          Log.Error Err.Description

          Exit Sub

        End If  

        

      End If



     

      lColIndex = getColByIndex(grid, sColCaption)

     

      ' Find the cell left and cell top, abnd cell height

      grid.Row = rowIndex

      grid.Col = lColIndex

      lLeft = grid.CellLeft()

      lTop = grid.CellTop()

      lHeight = grid.CellHeight()

        

     

      ' Calculates the horizontal coordinates of the cell (in VB twips)

      'xTwips = grid.Columns(column).Left + (grid.Columns(column).Width / 2)

      xTwips = lLeft+ (grid.Columns(lColIndex).Width / 2)

      ' Converts twips to pixels

      x = CLng(TwipsToPixelsX(xTwips))



      ' Calculates the vertical coordinates of the cell (in VB twips)

      'yTwips = grid.RowTop(rowIndexV) + grid.RowHeight / 2

      yTwips = lTop + lHeight / 2

      ' Converts twips to pixels

      y = CLng(TwipsToPixelsY(yTwips))



      ' Clicks the specified cell

      grid.Click x, y, tShift



    End Sub '' ClickCellEx