Domanda

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?

È stato utile?

Soluzione

Try this code:

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

Altri suggerimenti

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];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top