本文介绍了如何创建复选框运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我在运行时在gridview中创建复选框。

但我遇到的一个问题是我使用复选框,当我检查复选框然后datagridview填充数据并自动创建一个复选框行。

问题是

当我取消选中chekbox然后datagrid视图数据源是空的,当我再次选中复选框时,它会创建两个复选框,每行内有一行网格视图....

当我再次取消选中复选框并再次选中复选框,然后在网格视图中创建三个复选框任何一个帮助我如何停止多重检查在网格视图中创建的框。

---------------------------------- -------------------------------------------

我只想要一个包含所有行的复选框



我试试这个代码

当复选框检查状态改变时运行此代码



我尝试过:



私人无效isacti veOffercheckBox_CheckedChanged(object sender,EventArgs e)
{
if(isactiveOffercheckBox.Checked == true)
{
OfferdataGridView.DataSource = null;
OfferdataGridView.DataSource = GetofferfromDb();
DataGridViewCheckBoxColumn chekbox = new DataGridViewCheckBoxColumn();
chekbox.HeaderText =chekbox;
chekbox.Name =chekbox;
OfferdataGridView.Columns.Add(chekbox);
OfferdataGridView.Enabled = true;
OfferdataGridView.Height = 146;
}
其他
{
OfferdataGridView.DataSource = null;
OfferdataGridView.Enabled = false;
}
}
解决方案

Hi every one i create check box in gridview on runtime.
But one problem i face i use check box when i checke the check box then datagridview fill with data and automatical create one checkbox in one row.
problem is that
when i uncheck the chekbox then datagrid view datasource is empaty and when i check the check box again then it create two check box with every row inside the grid view....
And when i again uncheck the check box and again checked the check box then it create three check box inside the grid view any one help me how can i stop the multiple check box that created inside the grid view.
-----------------------------------------------------------------------------
I want only one check box with all the rows

I try this code
this code is run when checkbox check sate is changed

What I have tried:

private void isactiveOffercheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (isactiveOffercheckBox.Checked == true)
            {
                OfferdataGridView.DataSource = null;
                OfferdataGridView.DataSource = GetofferfromDb();
                DataGridViewCheckBoxColumn chekbox = new DataGridViewCheckBoxColumn();
                chekbox.HeaderText = "chekbox";
                chekbox.Name = "chekbox";
                OfferdataGridView.Columns.Add(chekbox);               
                OfferdataGridView.Enabled = true;
                OfferdataGridView.Height = 146;               
            }
            else           
            {             
                OfferdataGridView.DataSource = null;
                OfferdataGridView.Enabled = false;                
            }
        }
解决方案


这篇关于如何创建复选框运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 16:28