Tarun Tak
Tarun Tak

Reputation: 411

Initialize DataRow object with DataGridView Selected row

Window c# Desktop Application

I want to initialize a DataRow object with the selected row of DataGrdView.

Is it possible if yes then how?

I am writting the followind code and it is giving compilation error.

DataRow dr = (DataRow)DataGridView1.SelectedRows[0];

Thanks

Upvotes: 1

Views: 2240

Answers (2)

Dummy01
Dummy01

Reputation: 1995

Try this:

DataRow dr = (DataGridView1.SelectedRows[0].DataBoundItem as DataRowView).Row;

Upvotes: 2

Prakash
Prakash

Reputation: 823

try this

DataRow dr = (dataGridView1.SelectedRows[0].DataBoundItem as DataRowView).Row;

Upvotes: 1

Related Questions