如何勾选所有复选框
How to tick all checkboxes
我的 form.Its 上有一个 gridview 控件,第一列是复选框列,另一列 textboxcolumn.I 正在用来自列表
的一些字符串值填充文本框列
像这样
for (int i = 0; i < listeList.Count; i++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[1].Value = listeList[i];
}
我想做的是 select 用户单击按钮后 gridview 中的所有复选框我该怎么做
这是我试过的
private void btnselectAll_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
// row.Cells[0].Value = "true";
//if (row.Cells[0].Value != ull)
//{
// if (Convert.ToBoolean(row.Cells[0].Value))
// {
// MessageBox.Show(row.Cells[1].Value.ToString());
// }
//}
}
}
将适当的单元格投射到 DataGridViewCheckBoxCell
:
for(int row = 0; row < this.dataGridView1.Rows.Count; row++)
{
var chkCell = dataGridView1[0, row] as DataGridViewCheckBoxCell;
// read:
bool isChecked = (bool)chkCell.EditedFormattedValue;
// assign:
chkCell.Value = true;
}
我的 form.Its 上有一个 gridview 控件,第一列是复选框列,另一列 textboxcolumn.I 正在用来自列表
的一些字符串值填充文本框列像这样
for (int i = 0; i < listeList.Count; i++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[1].Value = listeList[i];
}
我想做的是 select 用户单击按钮后 gridview 中的所有复选框我该怎么做
这是我试过的
private void btnselectAll_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
// row.Cells[0].Value = "true";
//if (row.Cells[0].Value != ull)
//{
// if (Convert.ToBoolean(row.Cells[0].Value))
// {
// MessageBox.Show(row.Cells[1].Value.ToString());
// }
//}
}
}
将适当的单元格投射到 DataGridViewCheckBoxCell
:
for(int row = 0; row < this.dataGridView1.Rows.Count; row++)
{
var chkCell = dataGridView1[0, row] as DataGridViewCheckBoxCell;
// read:
bool isChecked = (bool)chkCell.EditedFormattedValue;
// assign:
chkCell.Value = true;
}