这妞不错!

会有那么一天...

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

        #region 事件--表格CellContentClick(DGV中checkBox单选)
        private void dgvInfo2_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)        {
            if (e.RowIndex > -1 && e.ColumnIndex > -1)//屏蔽表头、列头
            {
                if (e.ColumnIndex == 0)//注释此行代码,即点击行的任何列都勾选当前数据(e.ColumnIndex == 0设置为勾选列)
                {
                    DataGridViewCheckBoxCell checkCell;
                    for (int i = 0; i < dgvInfo2.Rows.Count; i++)
                    {
                        checkCell = (DataGridViewCheckBoxCell)dgvInfo2.Rows[i].Cells[0];
                        checkCell.Value = false;
                    }
                    checkCell = (DataGridViewCheckBoxCell)dgvInfo2.Rows[e.RowIndex].Cells[0];
                    checkCell.Value = true;
                }
            }
        }
        #endregion 

//------------------------------------------------------------------表格右键菜单 全选/取消全选

 

#region 表格右键菜单 全选/取消全选
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (dgvInfo.Rows.Count > 0)
            {
                dgvInfo.EndEdit();//提交表格
                for (int i = 0; i < dgvInfo.Rows.Count; i++)
                {
                    dgvInfo.Rows[i].Cells[0].Value = true;
                }
            }
        }
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            if (dgvInfo.Rows.Count > 0)
            {
                dgvInfo.EndEdit();//提交表格
                for (int i = 0; i < dgvInfo.Rows.Count; i++)
                {
                    dgvInfo.Rows[i].Cells[0].Value = false;
                }
            }
        }
        #endregion

 

     #region 表格中数值转换
            foreach (DataGridViewRow dgvRow in _frm.dgvInfo.Rows)
            {
                dgvRow.Cells["IsSave"].Value = false;//赋值为false,保存取值时用到
            }
            #endregion

 

        //    int counts = 0;
        //    foreach (DataGridViewRow row in _frm.dgvInfo.Rows)
        //    {
        //        if (row.Cells["IsSave"].Value.ToString() == "True")//只取勾选上的数据
        //        {
        //            counts++;
        //        }
        //    }
        //    if (counts == 0)//保存前先勾选数据
        //    {
        //        MessageBox.Show("请先勾选需要操作的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        //        return;
        //    }

 

posted on 2012-03-29 20:07  这妞不错  阅读(2126)  评论(0编辑  收藏  举报