zoukankan      html  css  js  c++  java
  • 让dataGridView中的复选框选中(winform)

    1:通过列的值让dataGridView中的复选框选中
    一个简单而实用的方法:
    public void SelectNewAddedItem(string strItems)
            {
                for (int i = 0; i < dataGridView1.RowCount; i++)
                {
                    string re_value = dataGridView1.Rows[i].Cells[2].EditedFormattedValue.ToString();
                    if (re_value == strItems)
                    {
                        dataGridView1.Rows[i].Selected = true;
                        this.dataGridView1["col_Select", i].Value = true;
                        break;
                    }
                }
            }
    “col_Select”是复选框所在列的列名。


    2:C/S模式下的 DataGridView里的复选框有没有被点击过呢?  
    程序一运行,DataGridView里的复选框有些被选择了的,如果用户勾掉已经选择的,或者勾上没有选择的。怎么判断呢?
    if(dataGridView1.Rows[i].Cells[j].Value!=null && dataGridView1.Rows[i].Cells[j].Value.ToString().trim()!="")
    {
    if(Convert.ToBoolean(dataGridView1.Rows[i].Cells[j].Value)==true)
    {
        MessageBox.Show("selected");
    }
    else
    {
    MessageBox.Show("not selected");
    }
    }
    else
    {
    MessageBox.Show("not selected");
    }

    for (int i = 0; i < this.dataGridView1.RowCount; i++)
    {
        if(dataGridView1.Rows[i].Cells[0].Value = true)
      {
         MessageBox.Show("选中的");
      }
      else
      {
         MessageBox.Show("没有选中的");
      }
    }

  • 相关阅读:
    素数筛选法
    一种美-无法言语
    动态规划-钢条切割问题
    动态规划《开篇》
    判断两序列是否为同一棵二叉搜索树
    C++字符串转化为数字的库函数
    C++字符串类型和数字之间的转换
    遍历二叉树的非递归实现
    关于二叉树的问题1-已知前序,中序求后序遍历
    获取回车事件
  • 原文地址:https://www.cnblogs.com/chenbg2001/p/1739011.html
Copyright © 2011-2022 走看看