01-29-2024, 12:47 PM
// 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];
}
}
}