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("没有选中的");
      }
    }

  • 相关阅读:
    HTML5移动开发修改APP名称
    JS保留字
    基于MVC的JagaScript Web 富应用开发
    继承的另一种写法
    设置MIME使虚拟空间可以下载APK文件
    HTML5移动开发修改APP图标
    Acer Travelmate T3290笔记本拆机指南
    SQL语法用like %或in时Parameters要怎么用才能避免SQL Injection的问题
    DirectShow编译过程(转载+修改)
    webclient很好很强大
  • 原文地址:https://www.cnblogs.com/chenbg2001/p/1739011.html
Copyright © 2011-2022 走看看