wpf datagridview复选框列选择无法正常工作. [英] wpf datagridview checkbox column selection not working fine.

查看:82
本文介绍了wpf datagridview复选框列选择无法正常工作.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(不确定是在正确的论坛中发布还是对此感到抱歉)

专家,
在基于c#.net Windows的wpf应用程序中添加了我的代码.一个datagridview.
我动态地向该datagridview添加了checkboxcolumn


(Im not sure wether i posted in the correct forum or not sorry for that)

Hi Experts,
in my c#.net windows based wpf application i added  a datagridview.
dynamically i added checkboxcolumn to that datagridview


DataGridViewCheckBoxColumn cbCol = new DataGridViewCheckBoxColumn();

            GridSource.Columns.Add(cbCol);


另一列是字符串.在此列中对值进行硬编码



and another column is string. to this column am hardcoding the values


             DataTable _datatable = new DataTable();



            _datatable.Columns.Add("Name", typeof(string));

            _datatable.Rows.Add("CSRs");

            _datatable.Rows.Add("Customers");





            GridSource.DataSource = _datatable;


直到这里我得到了两列(复选框和名称)
,当我试图检查那些复选框出现问题时.
我试图获取我在下面使用的已检查行的计数代码



till here fine am getting two columns (checkbox and Name)
when i am trying to check those checkboxes problem comming.
am trying to get the count of the checked rows for that i used below code


        int cbcount = 0;

            foreach (DataGridViewRow _dgRow in GridSource.Rows)

            {

                if ((bool)_dgRow.Cells[0].Value)

                    cbcount++;

            }



cbcount将给出检查的计数.

但是这里出现的问题
如果我检查2行,则给出1
如果我检查5行,则给出给4
如果我检查1行就给我0
意味着得到n-1个结果

我做错了吗??



cbcount will give the checked count.

but the problem raising here
if i check 2 rows it giving 1
if i check 5 rows it giving 4
if i check 1 row it giving me 0
means am getting n-1 result

where i did wrong??

推荐答案

与您相同.谁能帮助我plz ??? !!!!!
the same to you.Who helps me plz???!!!!!


这篇关于wpf datagridview复选框列选择无法正常工作.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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