• DataGridView中DataGridViewCheckBoxCell 控制选中


    关于DataGridView中DataGridViewCheckBoxCell 控制选中,以下是单选实现,需要设置该列readonly属性为ture,否则只有当选中其他时才会有反应!

    以下部分代码

     dgv.CommitEdit(DataGridViewDataErrorContexts.Commit);
                    DataGridViewCheckBoxCell chktmp 
    = (DataGridViewCheckBoxCell)dgv.Rows[e.RowIndex].Cells["chk"];
                    
    if (!(bool)chktmp.FormattedValue)
                    {
                        chktmp.Value 
    = true;
                    }
                    
    for (int i = 0; i < dgvAccount.Rows.Count; i++)
                    {
                       
                        
    if ( i != e.RowIndex)
                        {
                       
                            DataGridViewCheckBoxCell chk 
    = (DataGridViewCheckBoxCell)dgv.Rows[i].Cells["chk"];
                            chk.Value 
    = false;
                        }

                    }

     判断是否选中

     for (int i = 0; i < dgv.Rows.Count ; i++)
                {
                    dgv.CommitEdit(DataGridViewDataErrorContexts.Commit);
                    DataGridViewCheckBoxCell chk 
    = (DataGridViewCheckBoxCell)dgv.Rows[i].Cells["chk"];
                    
    if (chk != null && (bool)chk.FormattedValue)
                    {
                            
                    }
                }
  • 相关阅读:
    [GoogleInterview]连续子序列问题
    [Codeforces #615 div3]1294E Obtain a Permutation
    重识线段树——Let's start with the start.
    [易语言][ExDui][Tutorial]1.NameSelector
    [LuoguP1025][数据加强]数的划分
    [易语言][ExDui][Tutorial]0.Hello,world!
    Hello,cnblog!
    棋牌覆盖问题(分治)
    UVA 11732题解
    LA 3942Remember the Word
  • 原文地址:https://www.cnblogs.com/skyblue/p/2073145.html
Copyright © 2020-2023  润新知