Question

I have a datagridview that filled by a DataTable's Data; I want to get DataGridView's current selected row and pass this row as a DataRow to another form in dataGridView1_CellDoubleClick Event of my DataGridView. I tried this code:

int rw = dataGridView1.CurrentRow.Index
DataRow PassingSessionInfo;
PassingSessionInfo = SessionsData.NewRow();
PassingSessionInfo = dataGridView1.Rows[rw];

and SessionsInfo is a DataTable. I Got error, could you please help me?

Était-ce utile?

La solution

Try this code:

int rw = dataGridView1.CurrentRow.Index
DataRow PassingSessionInfo;
PassingSessionInfo = ((dataGridView1.DataSource) as DataTable).Rows[rw];

Autres conseils

PLease Try

int rw = dataGridView1.CurrentRow.Index
DataRow PassingSessionInfo;
PassingSessionInfo = SessionsData.NewRow();

DataTable dt = (DataTable)dataGridView1.DataSource;
dt.Rows.Add(dataGridView1.Rows[rw]);

PassingSessionInfo = dt.Rows[0];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top