Forum Discussion

vthomeschoolmom's avatar
vthomeschoolmom
Super Contributor
13 years ago

ComponentOne truedbgrid pro 8 in VB 6 ActiveX project

So I have a hard time accepting cannot be done. And I REALLY hate unstable scripts that won't run on different resolutions and whatnot. So I hate coordinates. I have a grid on a form. When the user clicks on the row selector, a button becomes enabled. I need to simulate clicking on the row selector. The native properties and methods of that grid do expose somethings that looks like it selects the row BUT selecting the row programatically does not fire the event that causes the change in the state of the button which I need enabled so I can click on it.



Is there a way to calculate the coordinates of say a particular row and column? Does anyone have any thoughts on how I can get in there? Thanks



S

7 Replies

  • For anyone who using this for a grid in storage mode, instead of

    grid.Bookmark = CDbl(rowIndex + 1) ' In our example, the Bookmark property holds the 1-based row index and is of the Double type



    Just do grid.Row = rowIndex
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    have you tried looking for the method on the grid or page or whatnot that executes when the event occurs?  This is what I've done before in the past.  So, you use the native methods to simulate the click, there's probably a native method then to simulate the event afterwards.  so you're code (in pseudo) would look like



    MyGrid.RowSelector.NativeClick()

    MyGrid.DoOnClickEvent()
  • I cannot because the event afterward that fires is declared private in VB. It is not accessible even to other code within the application, let alone to me.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Hrm... there are ways of getting access to private declarations in automation.



    According to the help



    Note that by default protected and private properties are not displayed in the Object Browser and other dialogs and panels, however, these properties are available in scripts. To make them visible you should enable the Show hidden members option in the Engines - General Options dialog. See Access to Properties for more information.




    Does this help?
  • Nope. It is not a property or method, it is an event. And a private one at that. I ran some tests trying to run code that is not exposed by the UI from a dummy VB6 app. I added a public sub to the form. I tried to call the public sub that is in the form. Can't. This makes sense based on the way ActiveX exposes stuff through properties and methods.


  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Lane,



    The TrueDBGrid control does have properties and methods for calculating coordinates of grid elements, such as RowTop, RowHeight, RecordSelectorWidth and so on. I've put this all together and, after some experimenting, come up with the following function that calculates coordinates of a grid row indicator given the row index and then clicks on it:



    ' Click the indicator of the grid row specified by the 0-based index

    Sub ClickRowIndicator(grid, rowIndex)

      If rowIndex < 0 Or rowIndex >= grid.ApproxCount Then

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

        Exit Sub

      End If



      If Not grid.RecordSelectors Then

        Log.Error "Cannot click the row indicator because they are not displayed in the grid."

        Exit Sub

      End If



      ' Set the current row and scroll the grid to make it visible

      grid.Bookmark = CDbl(rowIndex + 1) ' In our example, the Bookmark property holds the 1-based row index and is of the Double type



      Dim x, y, xTwips, yTwips



      ' Calculate coordinates of the row indicator, in VB twips

      xTwips = grid.RecordSelectorWidth / 2

      yTwips = grid.RowTop(grid.Row) + grid.RowHeight/2



      ' Convert twips to pixels

      x = CLng(TwipsToPixelsX(xTwips))

      y = CLng(TwipsToPixelsY(yTwips))



      Log.Message "Clicking indicator of grid row " & rowIndex & "..."

      grid.Click x, y

    End Sub





    Const TWIPSPERINCH = 1440



    Function TwipsToPixelsX(XTwips)

      Dim Xdpi

      Xdpi = Win32API.GetDeviceCaps(Win32API.GetDC(0), Win32API.LOGPIXELSX)

      TwipsToPixelsX = XTwips / TWIPSPERINCH * Xdpi

    End Function



    Function TwipsToPixelsY(YTwips)

      Dim Ydpi

      Ydpi = Win32API.GetDeviceCaps(Win32API.GetDC(0), Win32API.LOGPIXELSY)

      TwipsToPixelsY = YTwips / TWIPSPERINCH * Ydpi

    End Function


    Usage example:



    Sub Test

      Dim grid

      Set grid = Sys.Process("Ub2RsCls").VBObject("UB2ADO").VBObject("TDBGrid1")



      ClickRowIndicator grid, 0

      ClickRowIndicator grid, 3

      ClickRowIndicator grid, 7

    End Sub



    You may need to tweak the code slightly for your specific grid object (e.g. if it uses splits). Anyway, give it a try and let me know how it works for you.