1
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();"

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Alphatrix
  • 83
  • 8
  • I found the answer int i = c1TrueDBGrid1.Row; try { txtbox_name.Text = c1TrueDBGrid1[i, 1].ToString(); } catch { MessageBox.Show("Error Occurred while binding."); } – Alphatrix Mar 01 '18 at 06:30
  • You've found the answer and posed it 41 minutes after I've written my answer, that contains exactly the same code. How lovely. – Zohar Peled Mar 01 '18 at 06:33

1 Answers1

3

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.

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121