private void dgvWebSiteOrder_CellClick(object sender, DataGridViewCellEventArgs e)
        {

          //此事件里面不能获取
          if (row.Cells[this.colSelect.Name].Value != null && row.Cells[this.colSelect.Name].Value.ToString() == "1"
        }

  private void dgvLinkOrderList_CellContentClick(object sender, DataGridViewCellEventArgs e)
  {
         //此事件里面不能获取
         if (e.ColumnIndex < 0 || e.RowIndex < 0)
            {
                return;
            }
    
  }

//此事件里面可以获取
 private void dgvWebSiteOrder_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            List<DataGridViewRow> selectRows = new List<DataGridViewRow>();
            //点击的是第一列。
            if (e.ColumnIndex == 0)
            {
                foreach (DataGridViewRow row in this.dgvWebSiteOrder.Rows)
                {
                    if (row.Cells[this.colSelect.Name].Value != null && row.Cells[this.colSelect.Name].Value.ToString() == "1")
                    {
                        selectRows.Add(row);
                    }
                }
            }
            DgvSelectRows = selectRows;
        }

 

本文转载http://www.cnblogs.com/gossip/archive/2008/12/02/1346047.html

   不知道大家有没有这样的经验,当点击或者取消datagridview的checkbox列时,比较难获得其状态是选中还是未选中,进而不好进行其它操作,下面就列出它的解决办法:

主要用到了datagridview的CurrentCellDirtyStateChanged和CellValueChanged两个事件

CurrentCellDirtyStateChanged事件是提交对checkbox状态的修改

CellValueChanged事件是当状态提交后,也就是单元格值改变后做一些其它的操作,这里是将checkbox列的true或false状态作为tooptiptext属性设置到同一行的button列

CurrentCellDirtyStateChanged事件代码 :

.dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}

CellValueChanged事件代码 :

            }
        }

   不知道大家有没有这样的经验,当点击或者取消datagridview的checkbox列时,比较难获得其状态是选中还是未选中,进而不好进行其它操作,下面就列出它的解决办法:

主要用到了datagridview的CurrentCellDirtyStateChanged和CellValueChanged两个事件

CurrentCellDirtyStateChanged事件是提交对checkbox状态的修改

CellValueChanged事件是当状态提交后,也就是单元格值改变后做一些其它的操作,这里是将checkbox列的true或false状态作为tooptiptext属性设置到同一行的button列

CurrentCellDirtyStateChanged事件代码 :

.dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}

CellValueChanged事件代码 :

            }
        }

相关文章:

  • 2021-07-29
  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
猜你喜欢
  • 2021-11-23
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案