Reputation: 79
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
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
Reputation: 166406
Selected Cells is a property not a method.
DataGridView.SelectedCells Property
How to: Get the Selected Cells, Rows, and Columns in the Windows Forms DataGridView Control
Upvotes: 3