agaragaragar
agaragaragar

Reputation: 79

using System.Windows.Forms.Datagrid

Coding on Visual C# since a few days ago. Trying to access the elements in a DataGrid using the following code

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    textBox2.Text = this.dataGridView1.SelectedCells().Value;
}

Throws the next exception

Non-invocable member 'System.Windows.Forms.DataGridView.SelectedCells' cannot be used like a method.

What's the problem with SelectedCells then? What's the best practice?

EDIT: I guess I'll just convert the member to string and see how it goes.

Upvotes: 2

Views: 1754

Answers (2)

Ando
Ando

Reputation: 11409

From Msdn: DataGridView.SelectedCells - Gets the collection of cells selected by the user.

Test to see if SelectedCell.Count = 1 (only one cell was selected) then textBox2.Text = SelectedCells(0).Value

Alternativelly try using the CurrentCell property.

Upvotes: 1

Related Questions