.Net/Winform
C# DataGridView 체크 유무 확인하기
동구밖과수원
2012. 9. 25. 13:56
public partial class TestCheckBoxInGridView : Form { public TestCheckBoxInGridView() { InitializeComponent(); } private void TestCheckBoxInGridView_Load(object sender, EventArgs e) { this.dataGridView.Rows.Add(false, "test1"); this.dataGridView.Rows.Add(false, "test2"); } private void button_check_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); sb.Append("체크된 항목 : \r\n"); for(int i=0;i<this.dataGridView.Rows.Count;i++) { DataGridViewRow dr = this.dataGridView.Rows[i]; bool state = (bool)dr.Cells[0].Value; if (state == true) { sb.AppendLine(dr.Cells[1].Value.ToString()); } } MessageBox.Show(sb.ToString()); } }