2017-12-27 66 views
-1

내 코드를 가지고 :선택 값은

DataGrid

그리고 지금 내가있는 계정을 기반으로 몇 가지 작업을 수행 할 : 다음과 같은 출력을 생성

DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn(); 
actGrid.Columns.Add(chk); 
chk.HeaderText = "Select"; 
chk.Name = "select"; 
chk.ReadOnly = false; 

DataGridViewTextBoxColumn mc_no = new DataGridViewTextBoxColumn(); 
actGrid.Columns.Add(mc_no); 
mc_no.HeaderText = "M/C Number"; 
mc_no.Name = "mc_no"; 
mc_no.Width = 200; 
mc_no.ReadOnly = true; 

DataGridViewTextBoxColumn act_name = new DataGridViewTextBoxColumn(); 
actGrid.Columns.Add(act_name); 
act_name.HeaderText = "Name"; 
act_name.Name = "member"; 
act_name.Width = 262; 
act_name.ReadOnly = true; 

while (DR.Read()) 
{ 
    actGrid.Rows.Add(true, DR.GetInt32(0).ToString(), DR.GetString(2) + " " + DR.GetString(1)); 
} 

(후행 확인란을 전환하여), 특히 M/C 번호가 선택되었습니다.

답변

1
// iterate over DataGridView rows 
foreach (DataGridViewRow row in actGrid.Rows) 
{ 
    // check, if row is selected by checkbox 
    if (Equals(row.Cells["select"].Value, true)) 
    { 
     // get values for selected row 
     var mc_no_Value = (string)row.Cells["mc_no"].Value; 
     var member_Value = (string)row.Cells["member"].Value; 

     // do smth with values here 
    } 
}