C# 无法选中带有复选框的数据绑定Datagidview

C# 无法选中带有复选框的数据绑定Datagidview,c#,winforms,datagridview,C#,Winforms,Datagridview,我有一个datagridview,它绑定到SQL server中的数据库,我在第一列中设置了一个复选框,当我运行程序时,该复选框无法被选中。这是为什么?数据库和复选框之间是否存在冲突?请。我非常需要帮助。多谢各位 我尝试将datagridview属性设置为ReadOnly=true,将编辑功能设置为true,但这些都不起作用 C#Winform代码: private void dgvSummaryUnserviceable_CellContentClick(object sender, Data

我有一个
datagridview
,它绑定到SQL server中的数据库,我在第一列中设置了一个复选框,当我运行程序时,该复选框无法被选中。这是为什么?数据库和复选框之间是否存在冲突?请。我非常需要帮助。多谢各位

我尝试将
datagridview
属性设置为
ReadOnly=true
,将编辑功能设置为true,但这些都不起作用

C#Winform代码:

private void dgvSummaryUnserviceable_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
    try
        {
            if (dgvSummaryUnserviceable.Rows.Count == 0)
            {
                MessageBox.Show("No Items to Load.Choose Transaction type first", "Field Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);

            }
            else
            {
                if (cboTranstype.Text == "PAR")
                {

                    foreach (DataGridViewRow row in dgvSummaryUnserviceable.Rows)
                    {

                        bool isSelected = Convert.ToBoolean(row.Cells["colUnserviceable"].Value);
                        if (isSelected)
                        {

                            //getting the specific cell value in datagridview
                            if (dgvSummaryUnserviceable.SelectedCells.Count > 0)
                            {
                                emp_idno = row.Cells[5].Value.ToString();
                                MessageBox.Show("" + emp_idno);
                                T_type = cboTranstype.Text;
                                prop_no = row.Cells[9].Value.ToString();
                                qty = Convert.ToInt32(row.Cells[10].Value);
                            }

                        }
                        else
                        {
                            int iRows = dgvSummaryUnserviceable.Rows.Count;
                            int iCheckedCount = 0;

                            for (int i = 0; i < iRows; i++)
                            {
                                int iChecked = 0;
                                iChecked = Convert.ToInt32(dgvSummaryUnserviceable.Rows[i].Cells["colUnserviceable"].FormattedValue);
                                iCheckedCount += iChecked;
                            }//for

                            if (iCheckedCount == 0)
                            {

                                MessageBox.Show("Select first the Items you want to Transfer", "Field Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                                return;

                            }//if

                        }//else
                    }//foreach
                }//cboTranstype
            }//else
        }//try
        catch (Exception ex)
        {

            MessageBox.Show(ex.Message, "Try Catch Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
private void dgvSummaryUnservice_CellContentClick(对象发送方,DataGridViewCellEventArgs e)
{
尝试
{
if(dgvSummaryUnservicable.Rows.Count==0)
{
MessageBox.Show(“没有要加载的项目。首先选择事务类型”,“需要字段”,MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
其他的
{
如果(cboTranstype.Text==“PAR”)
{
foreach(DGVSummaryUnservicable.Rows中的DataGridViewRow行)
{
bool isSelected=Convert.ToBoolean(row.Cells[“colunservice”].Value);
如果(当选)
{
//在datagridview中获取特定单元格值
如果(DGVSummaryUnservice.SelectedCells.Count>0)
{
emp_idno=row.Cells[5].Value.ToString();
MessageBox.Show(“+emp_-idno”);
T_type=cboTranstype.Text;
prop_no=row.Cells[9]。Value.ToString();
数量=转换为32(行单元格[10].值);
}
}
其他的
{
int iRows=dgvSummaryUnservicable.Rows.Count;
int iCheckedCount=0;
for(int i=0;i
这是我的全部代码。该复选框未绑定到数据库,我只是在设计中添加了它,但我想使用它作为datagridview上特定记录的选择器,其中一些列绑定到数据库[datagridview的屏幕截图]

这是我的屏幕截图。记录加载到datagridview后,我将单击该复选框,但当我单击该复选框时,它无法被选中


如果要在datagridview中编辑数据,则需要将datagridview的
只读
属性设置为
启用
属性设置为

可以将特性设置为三个不同的图层 1.2完整数据网格视图 2.柱上 3.成排

在您的情况下,如果需要,第1列可以编辑铰孔而不是编辑(在完整的datagridview
Readonly
=false上),然后对其余列使属性为true。像这样

dataGridView1.Columns[1].ReadOnly=true

dataGridView1.Columns[2]。ReadOnly=true


评论不用于扩展讨论;此对话已完成。在生成复选框的逻辑中,如何为复选框分配唯一的
id
?您将如何使用此值在
DB
中执行您的操作?@rommel如果我的回答帮助您,那么您可以将答案勾选为已接受