Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not able to find datagrid row or cell not displayed on screen
#1
Hi Gintaras!
Long time QM user, first time posting.
a while back (2006?) you provided a QM Acc function to iterate through a .NET datagrid even when row and/or cell was not visible on screen. the function name is Acc.GetNetDataGridCell.

https://www.libreautomate.com/forum/show...taGridCell

trying to do the same but in LibreAutomate.
LibreAutomate it can capture all rows but it errors out when it reaches the row that is not visible unless the scrollbar pages down. it returns a null variable when it reaches the row.

can you help converting the QM function to LibreAutomate?

Member function Acc.GetNetDataGridCell
Code:
Copy      Help
function# nColumns [row] [col] [Acc&ac]

;Retrieves accessible object for specified cell in NET data grid.
;This object must be data grid. You can call this function multiple times with it.
;Returns the number of used rows.
;nColumns is the number of columns in the grid.
;row and col are 1-based row and column indexes.

;EXAMPLE
;Acc aGrid=acc("DataGrid" "TABLE" win("Customer Details" "WindowsForms10.Window.8.app4") "WindowsForms10.Window.8.app4" "" 0x1001)
;Acc aCell
;int i
;for i 0 aGrid.GetNetDataGridCell(11)
,;aGrid.GetNetDataGridCell(11 i+1 1 aCell)
,;out aCell.Value
,;;aCell.SetValue("new value")


int n=a.ChildCount-nColumns-2
if(&ac)
,if(row>n) end "row too big"
,str s.format("child%i child%i" row+nColumns+1 col)
,;out s
,;out &ac
,Navigate(s ac)
,
ret n
err+ end _error
#2
Code:
Copy      Help
// script ""
print.clear();

var w = wnd.find(1, "DataGrid Control Sample", "*.Window.*");
var e = w.Elm["TABLE", "DataGrid", "class=*.Window.*"].Find(1);
//print.it(e);
var g = new ElmWinformsOldDataGrid(e);
print.it($"{g.ColumnCount} columns, {g.RowCount} rows");
for (int row = 0; row < g.RowCount; row++) {
    print.it($"row {row + 1}: {g[row, 0].Value}, {g[row, 1].Value}, {g[row, 2].Value}");
}


class ElmWinformsOldDataGrid {
    elm[] _headers, _cells;
    
    /// <summary>
    ///
Finds all header and cell UI elements, and stores the elms in this variable.
    /// </summary>
    ///
<param name="table"></param>
    ///
<param name="ignoreLastRow"></param>
    public ElmWinformsOldDataGrid(elm table, bool ignoreLastRow = false) {
        _headers = table.Elm["COLUMNHEADER", prop: "level=0"].FindAll();
        _cells = table.Elm["CELL", prop: "level=0"].FindAll();
        ColumnCount = _headers.Length;
        RowCount = _cells.Length / _headers.Length - (ignoreLastRow ? 1 : 0);
    }

    
    public int ColumnCount { get; }
    
    public int RowCount { get; }
    
    public elm[] Headers => _headers;
    
    /// <summary>
    ///
Gets a cell UI element.
    /// </summary>
    ///
<param name="row">0-based row index.</param>
    ///
<param name="column">0-based column index.</param>
    ///
<exception cref="ArgumentOutOfRangeException"></exception>
    ///
<remarks>
    ///
This function is fast. All UI elements are cached by the constructor.
    /// </remarks>
    public elm this[int row, int column] {
        get {
            ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(row, RowCount);
            ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(column, ColumnCount);
            return _cells[row * ColumnCount + column];
        }
    }
}
#3
Hi Gintaras,
Thank you for your time... I should have attached the screenshots to better explain the issue.

I tweaked your ElmWinformsOldDataGrid class headers and _cells line to what my actual datagrid example. It only captures up to row 12 cells (until i page down). Rows 13 and greater look to be grayed out/dithered when using the spy/finder tool.  Here's a screenshot of how the grid is structure.


Attached Files Image(s)
           
#4
Need flag HiddenToo.
 
Code:
Copy      Help
        _cells = table.Elm["CELL", prop: "level=2", flags: EFFlags.HiddenToo].FindAll();
#5
Adding the hidden flag worked like a charm! Thank you!


Forum Jump:


Users browsing this thread: 1 Guest(s)