最近在做一个项目,WinForm里面会用到toolStripButton按钮 [新增][存檔][编辑][放弃]之类功能,搭配着dataGridView 但是管理按钮好麻烦尤其按钮比较多的时候,我要去控制例如
toolStripButton1.Enabled = true;
toolStripButton2.Enabled = false;
toolStripButton3.Enabled = true;
toolStripButton4.Enabled = false;有没有比较好的方法或思路可以有效地去控制哪个按钮要true or false?
范例:当dataGridView 有资料时,可以点[编辑],其他关闭,点了[编辑]后[存檔]也能选也能选[放弃]....
各位前辈大哥你们知道我意思吧~一直想不出如何有简洁的方法~
WinFormDataGridView管理

解决方案 »

  1.   

    真的只有 toolStripButtonXXX.Enabled = true or false;
      

  2.   

    你最好把按钮分类,比如一类按钮放在某个容器中,你就直接遍历这个容器中的按钮即可,不用写出每个按钮的名字,而且你还可以利用tag属性,和数据库中的权限做对应,这样就是一个简易的权限控制
      

  3.   

    “有效控制”的背后,其实也是一堆的true/false。现在你是完全自己实现而已
      

  4.   

    public void SetBtnEnable(bool bBtn1,bool bBtn2,bool bBtn3,bool bBtn4)
    {
    toolStripButton1.Enabled = bBtn1;
    toolStripButton2.Enabled = bBtn2;
    toolStripButton3.Enabled = bBtn3;
    toolStripButton4.Enabled = bBtn4;
    }能否简单点?
      

  5.   

    哈哈这一个方法有意思~ public void SetBtnEnable(bool bBtn1,bool bBtn2,bool bBtn3,bool bBtn4) 
    也许这过程真的省不了了,4楼