当我从Datagridview中取消选中复选框时,如何从Datagridview中删除值 [英] How To Remove The Values From Datagridview When I Uncheck The Checkbox From The Datagridview

查看:96
本文介绍了当我从Datagridview中取消选中复选框时,如何从Datagridview中删除值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个网格视图1. grid1,2.grid2 ..

grid1包含一个文本框列和第二个复选框列...如果我选中grid1对应的值的复选框添加到grid2 .. .if取消选中grid1中的复选框,从grid2中删除相应的值...

例如:



Grid1:



项目复选框

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

肥皂

电子产品



如果我检查肥皂和电子产品的数值从数据库添加到grid2 ...



Grid2:



子项目

--------

鸽子

梨子

CD / DVD

LCD / LED



如果我取消选中电子设备应该这样显示:

子项目

--------

鸽子

解决方案

  //  将计时器写入以下循环到计时器 

int j = 0 ; j < grid1.Rows.Count; j ++)
{
if (grid1.Rows [j] .Cells [ 0 ]。值!= null
{
布尔 b1 =(< span class =code-sdkkeyword> Boolean )grid1.Rows [j] .Cells [ 0 ]。值;
if (b1 == true
{
// 您可以在此处将值添加到第二个网格
// if(b1 == true)将值添加到第二个网格
// if(b1 == false)从第二个网格中删除值

// 重要的是,当您将值添加到第二个网格时,您应该在第二个网格中添加值soap和electronics。它应该在另一列中,该列应该在visible = false

// 根据此列,您可以在取消选中grid1中的复选框时删除项目
}
}
}


I have two gridviews 1. grid1 , 2.grid2..
grid1 contains one textbox column and second checkbox column...if i check the checkbox from grid1 corresponding values add to grid2...if uncheck the checkbox from grid1 the corresponding values remove from the grid2...
for example:

Grid1:

Item Checkbox
----- ---------
Soap "
Electronics "

if i check the soap and Electronics the values add from the database to grid2...

Grid2:

SubItems
--------
Dove
Pears
CD/DVD
LCD/LED

If i uncheck the Electronics It should be show like this:
SubItems
--------
Dove
Pears

解决方案

//Put the timer and write this below loop into the timer

for (int j = 0; j < grid1.Rows.Count; j++)
{
    if (grid1.Rows[j].Cells[0].Value != null)
    {                                
        Boolean b1 = (Boolean)grid1.Rows[j].Cells[0].Value;
        if (b1 == true)
        {
            //Here you can add the value to the second grid
            //if (b1==true) add the value to the second grid
            //if (b1==false) remove the value from the second grid
            
            //The important thing is, when you add the value to the second grid you should add the values soap and electronics also in the second grid. it should be in the another column and that column should be in visible = false
            
            //Based on this column you can remove the items when the checkbox is unchecked from the grid1
        }       
    }                          
}


这篇关于当我从Datagridview中取消选中复选框时,如何从Datagridview中删除值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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