Search code examples
c#componentonetruedbgrid

c1 TrueDBGrid cell value to textbox


private void c1TrueDBGrid1_Click(object sender, EventArgs e)
{


}

How can I get the value of a cell and then display it in a textbox. Just like this code that works for data grid view "OwnerIDtxtbox.Text = PetGrid.Rows[i].Cells[7].Value.ToString();"


Solution

  • c1TrueDBGrid exposes a couple of indexers that takes the row number as first parameter and the column name or index as the second - you can use either one of them.
    Please note that both returns object.

    var row = grid.Row; // get the current row
    
    var columnIndex = 0;
    var cellValue = grid[row, "ColumnName"];
    var cellValue = grid[row, columnIndex];
    

    Another option is to use

    var value = grid.Columns[0].CellValue(row);
    

    And of course, you can use the column's string indexer:

    var value = grid.Columns["Company"].CellValue(row)
    

    For more information, please refer to official documentation.