鼠标点击datagridview上的checkbox 没反应。请问是怎么回事呢?
我的代码如下:
public void DtToView(DataTable calldt)
{
dataGridViewX1.Rows.Clear();
dataGridViewX1.Columns.Clear();
dataGridViewX1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
dataGridViewX1.ReadOnly = true;
dataGridViewX1.ColumnCount = 5;
dataGridViewX1.ColumnHeadersVisible = true;
// Set the column header style.
DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
columnHeaderStyle.BackColor = Color.DarkSlateGray;
columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Regular);
dataGridViewX1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
//datagridview上新建添加的checkbox控件
DataGridViewCheckBoxColumn ck = new DataGridViewCheckBoxColumn();
//ck.TrueValue = true;
//ck.FalseValue = false;
dataGridViewX1.Columns.Insert(0, ck);
// Set the column header names.
dataGridViewX1.Columns[0].Name = "选择";
dataGridViewX1.Columns[1].Name = "id";
dataGridViewX1.Columns[2].Name = "callid";
dataGridViewX1.Columns[3].Name = "姓名";
dataGridViewX1.Columns[4].Name = "电话";
dataGridViewX1.Columns[5].Name = "状态";
dataGridViewX1.Columns[0].Width = 45;
dataGridViewX1.Columns[1].Visible = false;
dataGridViewX1.Columns[2].Visible = false;
dataGridViewX1.Columns[3].Width = 75;
dataGridViewX1.Columns[4].Width = 100;
dataGridViewX1.Columns[5].Width = 65;
dataGridViewX1.RowsDefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Regular);
for (int i = 0; i < calldt.Rows.Count; i++)
{
int index = this.dataGridViewX1.Rows.Add();
this.dataGridViewX1.Rows[index].Cells[1].Value = calldt.Rows[i][0].ToString();
this.dataGridViewX1.Rows[index].Cells[2].Value = calldt.Rows[i][1].ToString();
this.dataGridViewX1.Rows[index].Cells[3].Value = calldt.Rows[i][2].ToString();
this.dataGridViewX1.Rows[index].Cells[4].Value = calldt.Rows[i][3].ToString();
string status = calldt.Rows[i][4].ToString();
if (int.Parse(status) == 1)
{
//dataGridViewX1.Columns[0].ReadOnly = false;
this.dataGridViewX1.Rows[index].Cells[5].Value = "已分发";
}
else if (int.Parse(status) == 0)
{
//dataGridViewX1.Columns[0].ReadOnly = false;
this.dataGridViewX1.Rows[index].Cells[5].Value = "未分发";
}
}
}
看来你的问题很多,因为你设置了只读,所以无法选中,这种情况只能针对每一列设置只读,这样才可以
我也是在摸索着做,毕竟对于winform是个新手,谢谢你,方便要个你的联系方式吗?可以请教你,不方便也没关系。
@恶之必要: 你是女生吗?
@jqw2009: 对呀
@恶之必要: 15995685610 加微信吧
我设置了ReadOnly = false还是多选框勾选不上,请问再怎么设置呢