一、添加覆選框 ArrayList arr = new ArrayList(); public string checkboxName = "選擇"; void StandLibWin_Load(object sender, EventArgs e) { DataGridViewCheckBoxCo ...
一、添加覆選框
ArrayList arr = new ArrayList(); public string checkboxName = "選擇"; void StandLibWin_Load(object sender, EventArgs e) { DataGridViewCheckBoxColumn CheckColunms = new DataGridViewCheckBoxColumn(); CheckColunms.Name = checkboxName; CheckColunms.HeaderText = checkboxName; CheckColunms.Width = 60; CheckColunms.TrueValue = "1"; CheckColunms.FalseValue = "0"; dataGridView1.Columns.Insert(1, CheckColunms); dataGridView1.CellContentClick += DataGridView1_CellContentClick; }註冊添加checkBox
二、判斷選中狀態(此例添加一個ArrayList用來存儲選中行的標識)
void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex > -1) { if (dataGridView1.Columns[e.ColumnIndex].Name == checkboxName) { arr.Clear(); for (int i = 0; i < this.dataGridView1.Rows.Count; i++) { if ((bool)dataGridView1.Rows[i].Cells[checkboxName].EditedFormattedValue == true) { string vClickGridId = dataGridView1.Rows[i].Cells["標識"].Value.ToString(); arr.Add(vClickGridId); } } } } }遍歷選中添加Arraylist
=================完結線==============================