SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Jan 2007
    Posts
    19
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    GridView (.net) - How to select specific cells

    We're currently evaluating TestComplete to determine if it meets our needs.

    Our application is developed in .net Version 2.
    We have this listing screen that has been constructed with a "GridView" object.
    We must be able to click or double-click on a specific cell (row/column) (because each column provides different information = different result on the click event).

    What am I able to do?
    -Get specifics from a Cell
    rText = gridAssetListing.Item(x, y).Value

    -Select a row
    call gridAssetListing.SetFocus
    call gridAssetListing.ClearSelection
    call gridAssetListing.SelectRowRange(x, x, true)

    -Determe Contents of row via columns
    for x = 0 to ( 5 )
    call gridAssetListing.SetFocus
    call gridAssetListing.ClearSelection
    call gridAssetListing.SelectRowRange(x, x, true)

    for y = 2 to 4 '1 to (w2.get_ColumnCount /2 )
    rText = gridAssetListing.SelectedCells.Item(y).get_Value
    next
    next

    -Select an individual cell
    call gridAssetListing.ClearSelection
    call gridAssetListing.Item(x, y).set_Selected (true)

    What I can't figure out is how to click or double click on an individual cell.

    Any help in this matter would be very appreciated.

    Thank you in advance for your cooperation.

  2. #2
    Senior Member
    Join Date
    May 2004
    Posts
    1,196
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: GridView (.net) - How to select specific cells

    Hi Caivara,

    The following script demonstrates how you can double-click a cell in the Microsoft .NET DataGridView control. Please let me know if you have any questions.

    <font class="small">Code:</font><hr /><pre>' VBScript
    Sub Test
    Dim p, w, grid

    Set p = Sys.Process("MS DataGrid")
    Set w = p.WinFormsObject("Form1")
    Set grid = w.WinFormsObject("dataGridView1")
    Call DblClickOnCell(grid, 1, 1)
    End Sub

    Sub DblClickOnCell(DataGridView, RowIndex, ColumnIndex)
    Dim I, X, Y

    Set DataGridView.FirstDisplayedCell = DataGridView.Item(ColumnIndex, RowIndex)

    Y = DataGridView.ColumnHeadersHeight
    For i = DataGridView.FirstDisplayedCell.RowIndex To RowIndex - 1
    Y = Y + DataGridView.Rows.Item(i).Height
    Next
    Y = Y + DataGridView.Rows.Item(i).Height / 2

    X = DataGridView.RowHeadersWidth
    For I = DataGridView.FirstDisplayedCell.ColumnIndex To ColumnIndex - 1
    X = X + DataGridView.Columns.Item(i).Width
    Next
    X = X + DataGridView.Columns.Item(i).Width / 2

    Call DataGridView.DblClick(X, Y)
    End Sub</pre><hr />

    BTW, I recommend that you see the following posts on our blog that are devoted to working with the DataGridView control.

    http://www.automatedqa.com/community/Hom...02/Default.aspx
    http://www.automatedqa.com/community/Hom...taGridView.aspx
    http://www.automatedqa.com/community/Hom...ell-Values.aspx
    Best regards,
    David - SmartBear Support

  3. #3
    Junior Member
    Join Date
    Jan 2007
    Posts
    19
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: GridView (.net) - How to select specific cells

    Thank you very much.

    I found out how to do something similar.
    The problem is that the grid was buried and it took a while to find it before the information could be extracted.
    Here's an example of the code.

    function DataAsset_DoubleClick_Selection ( processApp, windowMain, searchColumn, searchValue)

    dim gridAssetListing
    dim counterColumn
    dim counterRow

    dim searchResult
    dim blnFound
    dim objPoint
    dim objDetails

    dim x

    SiteWorkOrders_DoubleClick_Selection = true


    set gridAssetListing = processApp.WinFormsObject("Window_123")
    set gridAssetListing = gridAssetListing.WinFormsObject("GridView", "")

    call gridAssetListing.set_FirstDisplayedScrollingRowInd ex (0)


    if (Not ( gridAssetListing.exists ) ) then
    log.error ( "'Assets - Listing - Grid' - does not exist." )
    SiteWorkOrders_DoubleClick_Selection = false
    exit function
    end if

    blnFound = false
    counterColumn = 0
    'Determine the number of the column you are searching for
    do
    searchResult = gridAssetListing.Columns.Item(counterColumn).Heade rText

    if (Not CBool( StrComp( Trim ( searchResult ), Trim ( searchColumn ), vbTextCompare ) ) ) then
    blnFound = true
    searchColumn = searchResult
    else
    counterColumn = counterColumn + 1
    end if
    loop while ( (NOT blnFound) and (counterColumn &lt; gridAssetListing.get_ColumnCount) )

    if (Not blnFound ) then
    log.error ("Cannot find the column: " + searchColumn)
    SiteWorkOrders_DoubleClick_Selection = false
    exit function
    end if

    counterRow = 0
    blnFound = false
    'Simulate the users function in moving down the list.
    'Make sure row is visible.
    do
    searchResult = gridAssetListing.Item(counterColumn, counterRow).get_Value
    call gridAssetListing.SetFocus
    x = 0
    do while ( (Not (gridAssetListing.Item(counterColumn, counterRow).get_Displayed) and (x &lt; 100) ) )
    call gridAssetListing.Keys("[Down]")
    x = x + 1
    loop

    call gridAssetListing.ClearSelection
    call gridAssetListing.SelectRowRange(counterRow, counterRow, true)

    if ( InStr( Trim (searchResult), Trim (searchValue) ) &gt; 0 ) then
    blnFound = true
    else
    counterRow = counterRow + 1
    end if
    loop while ( (NOT blnFound) and (counterRow &lt; gridAssetListing.get_RowCount) )

    if ( blnFound ) then
    set objDetails = gridAssetListing.Item(counterColumn, counterRow)

    RowCoordinates = CInt (objDetails.AccessibilityObject.Bounds.X) + 5
    ColumnCoordinates = CInt (objDetails.AccessibilityObject.Bounds.Y) + 5

    set objPoint = gridAssetListing.ScreenToWindow (RowCoordinates, ColumnCoordinates)
    call gridAssetListing.DblClick (objPoint.X, objPoint.Y, skNoShift)
    call Delay (2000)
    else
    log.error ("Cannot find the value: " + searchValue)
    SiteWorkOrders_DoubleClick_Selection = false
    exit function
    end if

    end function

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 04:26 AM.

Copyright BetaSoft Inc.