I am trying to get a value from a specific cell in a dataGridView.
I know how to choose a Row / Column but not at the same time.
I have tried to get the value from row 3 in column 2 like below. But I cant find a Column member to Rows like this.

dataGridView1->Rows[3]->Columns[2] ?

I tried something like this also but here I will get an Object^. I will need to have a String^ value.

Object^ Sel50 = dataGridView1[3, 2];

Dani AI

Generated

Brief notes and a few practical alternatives that complement 's and 's posts.

Selected-row vs direct access

  • Using the SelectedRows collection (what used) is fine when the user actually selected a full row and SelectionMode permits it. For programmatic reads it is safer to address the row/column you want explicitly so the code does not depend on UI selection.

Safety and displayed text

  • A cell's Value can be nullptr or DBNull::Value; attempting ->ToString() without checking can throw. When the goal is to get what the user actually sees (formatted), prefer the cell's FormattedValue. See the docs for DataGridViewCell.Value and DataGridViewCell.FormattedValue for details (DataGridViewCell.Value, DataGridViewCell.FormattedValue).

Example helper (C++/CLI) — safely return the displayed text for a cell

String^ GetCellText(System::Windows::Forms::DataGridView^ grid, int row, int col)
{
    if (grid == nullptr) return String::Empty;
    if (row < 0 || row >= grid->Rows->Count) return String::Empty;
    if (col < 0 || col >= grid->Columns->Count) return String::Empty;

    Object^ v = grid->Rows[row]->Cells[col]->FormattedValue;
    if (v == nullptr || v == System::DBNull::Value) return String::Empty;
    return v->ToString();
}

When the grid is data-bound

  • For strongly-typed access use the row's DataBoundItem and read from the underlying DataRowView rather than relying on the grid cell; this avoids formatting surprises. See DataGridViewRow.DataBoundItem for the pattern (DataBoundItem).

Event-based access

  • In cell events use the event args (e->RowIndex, e->ColumnIndex) rather than SelectedRows, which makes code robust for clicks or edits.

SelectionMode caveat

  • If code uses SelectedRows, check that grid->SelectionMode supports full-row selection and that SelectedRows->Count > 0 before indexing (SelectionMode).

These points handle the common pitfalls: index order confusion, null/DBNull, formatted vs raw value, selection-based assumptions, and data-bound scenarios.

I found out a solution:

String^ Number = dataGridView1->SelectedRows[0]->Cells[2]->Value->ToString();

datagridview->Rows[rowCnt]->Cells[1]->Value= rowCnt;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.