2014-01-06 3 views
1

DataTable의 데이터로 채워진 DataGridview가 있습니다. DataGridView의 현재 선택된 행을 가져와이 행을 다른 폼의 DataRow로 전달하려는 경우 dataGridView1_CellDoubleClick 내 DataGridView 이벤트.선택한 DataGridView 행을 DataRow로 가져 오기

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

SessionsInfo이 DataTable에 있습니다 : 이 코드를 시도했다. 오류가 발생했습니다. 제발 도와주세요.

+0

언급하십시오 당신의 DataRow가있는 DGV는 또한 현재 당신이 받고있다 오류를 언급 통과하고 싶은 어떤 DGV에서. –

+0

DataRow 변수에 DataGridview Row를 복사하려고합니다. –

+0

좋습니다, 제안 된 해결책을 시도하십시오. –

답변

0

이 코드를하려고 시도하십시오 :

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

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]; 
+0

DataGridView에서 DataRow 변수로 행을 복사하려면 모든 DatGrid 행을 DataTable에 복사하십시오. –

+0

이 오류 메시지가 표시됩니다. 입력 배열이이 테이블의 열 수보다 길다. –

+0

지금 시도하십시오. 나는 오류가 사라 졌다고 생각한다 – pravprab

관련 문제