Forum Discussion

darshan_gandhi's avatar
darshan_gandhi
Occasional Contributor
10 years ago
Solved

MSFlex Grid issue

Hi,



I am working on a Windows based application designed in VB6.

We are having a grid which is a MSFlex grid and inside that grid we have a ComboBox (in each cell) to select a specific value. But this combo box object is not enabled until we click on the grid.

Can someone please let me know how can we determine how we can code for clicking on a specific cell in the grid and then selecting the value. I tried recording and it gives me hard code value for CLick method.

I want somethin where I first identify the Column header and then click on specific cell using row index.

Also I wanted to know if we can capture the status(enabled/disabled) of the cells.

Just for the information, the grid properties does not have (.Cell) although it does have other cell related properties like (.CellWidth, .CellHeight).



Can someone please help me as I am stuck from last few days with no solution :(



Thanks,

Darshan Gandhi
  • As this grid is not supported there is no builtin method to click cell. however u can find the coodrinates of cell click onthe paricular celll. here is the sample code



       Msflexgrid.setfocus

        Msflexgrid.row=1   'row Value

        Msflexgrid.col=1   'ColumnValue



            'to calculate the coordinates of the cell



            x=Msflexgrid.CellTop+form.Top

            y=Msflexgrid.CellLeft+form.Left



            'to convert twip into pixels



            twip_pixel_ratio = form.ScaleWidth / form.Width

            x = x/twip_pixel_ratio

            y = y/twip_pixel_ratio





    Call Msflexgrid.Click( y ,x)  'Clicks the 1st cell

9 Replies

  • murugans1011's avatar
    murugans1011
    Regular Contributor
    As this grid is not supported there is no builtin method to click cell. however u can find the coodrinates of cell click onthe paricular celll. here is the sample code



       Msflexgrid.setfocus

        Msflexgrid.row=1   'row Value

        Msflexgrid.col=1   'ColumnValue



            'to calculate the coordinates of the cell



            x=Msflexgrid.CellTop+form.Top

            y=Msflexgrid.CellLeft+form.Left



            'to convert twip into pixels



            twip_pixel_ratio = form.ScaleWidth / form.Width

            x = x/twip_pixel_ratio

            y = y/twip_pixel_ratio





    Call Msflexgrid.Click( y ,x)  'Clicks the 1st cell

  • murugans1011's avatar
    murugans1011
    Regular Contributor
    Hi Ms flexgrid is a unsupported   grid in tc. so there is no special method available in tc to work with that control. however u can work with the native properties of tat control to access grid



    'To focus on particular cell use



    Msflexgrid.SetFocus

    Msflexgrid.row=1 'row value

    Msflexgrid.col=1  'Column value



    as for combo box first map the object and get focus on particular cell asper above method and click on the item



    ComboBox.ClickItem "Item"



    U can also get grid cell data using textmatrix property



    CellValue=Msflexgrid.Textmatrix(1,1)

     A sample code to get cell contents

    http://support.smartbear.com/viewarticle/62627/
  • darshan_gandhi's avatar
    darshan_gandhi
    Occasional Contributor
    Thank you Murugan for your prompt reply.



    But unfortunately, Test Complete gives error in Test Results: "The window cannot get focus" for .Setfocus property.



    Anything more fruitful would be appreciated.



    Thanks,

    Darshan Gandhi
  • murugans1011's avatar
    murugans1011
    Regular Contributor
    Hi,



    Make sure that the grid enbled by using enabled property



    if Msflexgrid.Enabled then

      ..............

       Msflexgrid.setfocus

      .............

    End if



    after that try to use setfocus property

  • darshan_gandhi's avatar
    darshan_gandhi
    Occasional Contributor
    Hi,



    Had tried that initially itself. But no luck :(



    Any other options left as this grid is an integral part of the application and if that does not work, it will not make sense automating rest of the functions.



    Thanks,

    Darshan
  • murugans1011's avatar
    murugans1011
    Regular Contributor
    Can u pls provide screen shot and mapped name of the grid if possible. also make sure grid is visible onscreen.



    does this coding for u?





    Sub TestFlexGrid(ColumnName)

      Dim p, w, ColIdx, i, s



      Set p = Sys.Process("MyProject")

      Set w = p.VBObject("Form1").VBObject("MSFlexGrid1")

      ' Search for the column index

      ColIdx = -1

      For i = 0 To w.Cols - 1

        If w.TextMatrix(0, i) = ColumnName Then

          ColIdx = i

          Exit For

        End If

      Next

      ' If the column was not found...

      If ColIdx = -1 Then

        ' Post warning to the test log

        Log.Warning "Column '" & ColumnName & "' was not found."

      Else

        ' Retrieve data from the column cells

        For i = 1 To w.Rows - 1

          s = w.TextMatrix(i, ColIdx)

          Log.Message s

        Next

      End If

    End Sub



  • darshan_gandhi's avatar
    darshan_gandhi
    Occasional Contributor
    Hi,



    Sorry, but to share the screenshot will be difficult for me as we have data protection in place.



    But the code that you have shared works for me and I am able to find value in each cell using that code.

    Uusing that value I am able to find the Column header, but how do now I enter value in the cell which is below that column header and likewise for other cells.

    I dont want to use Click(x,y) as it brings hard coded values.



    Looking forward for your reply.



    Thanks,

    Darshan
  • murugans1011's avatar
    murugans1011
    Regular Contributor
    Hi, In my scenario each cell contains textbox. our developers created in such a way for user to enter text in the field. so if i click on the cell the textbox will be visible then i will enter text after pressing enter key record will be updated in grid.



       but in ur case it may be different. so u hav find how u manuall enter text in grid. so without knowing this, cannot able say how to insert record in grid. for input u can use  'keys' method to enter text in field. pls see the attached screenshot how textbox is visble in grid cell