Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not able to find datagrid row or cell not displayed on screen
#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];
        }
    }
}


Messages In This Thread
RE: Not able to find datagrid row or cell not displayed on screen - by Gintaras - 01-29-2024, 12:47 PM

Forum Jump:


Users browsing this thread: 4 Guest(s)