datagrid中复选框列的索引错误 [英] Wrong index of the checkbox column in datagrid

查看:71
本文介绍了datagrid中复选框列的索引错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码在datagrid的第3列添加一个复选框,但是这列的索引是0而不是3.有没有人理解这个错误以及如何修复它?谢谢



I have this code to add a checkbox to the 3rd column of the datagrid, but the index of this columns is 0 and not 3. Does anyone understand this error and how to fix it? Thanks

public void bloqselect()
       {
           DataGridViewCheckBoxColumn chkSelect = new DataGridViewCheckBoxColumn();
           chkSelect.Selected = false;
           chkSelect.HeaderText = "Bloqueador";
           chkSelect.Name = "chkSelect";
           grid_lic.Columns.Insert(3, chkSelect);

           if (chkSelect.Selected == true)

               bloqueador = 1;

           else
               bloqueador = 0;
       }

推荐答案

列数从0开始,这意味着第三列的索引将是2.



尝试

The column count starts at 0 which means that the index of the third column will be 2.

Try
grid_lic.Columns.Insert(2, chkSelect);


这篇关于datagrid中复选框列的索引错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆