根据某些匹配隐藏某些按钮

2023-12-28

如果符合以下规则,是否可以隐藏某些按钮? 以下是用于创建按钮列的代码和用于获取匹配项的代码。

我尝试过 BookButtonCell.Visible = false;,但它说它只是只读的。

Thanks.

 private void Form1_Load(object sender, EventArgs e)
     {          
            DataGridViewButtonColumn bookbutton = new DataGridViewButtonColumn();
            {
                bookbutton.HeaderText = "Book";
                bookbutton.Text = "Book";
                bookbutton.Name = "Book";
                bookbutton.UseColumnTextForButtonValue = true;
            }
            readalleventsdataGridView.Columns.Add(bookbutton); 


                int x = 0;
                foreach (DataGridViewRow gridRow in readalleventsdataGridView.Rows)
                {
                    DataGridViewCell BookButtonCell = gridRow.Cells["Book"];
                    DataGridViewCell EndDateCell = gridRow.Cells["EndDate"];
                    String StrTodayDate = DateTime.Now.ToString("dd/MM/yy");
                    DateTime TodayDate = Convert.ToDateTime(StrTodayDate);
                    String StrEndDate = EndDateCell.Value.ToString();
                    DateTime EndDate = Convert.ToDateTime(StrEndDate);
                    int result = DateTime.Compare(EndDate, TodayDate);
                    if (result < 0)
                        {
                          What Commands To Hide The Button?
                        }
                        x++;
                    }
        }

The 数据网格视图按钮列 http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewbuttoncell.aspx Visible http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.visible.aspx属性是只读属性。

尽管它看起来像一个按钮,但它仍然是一个DataGridViewButtonColumn,具有与人们所拥有的相同的可见性规则。所以缺点是你需要做拉维建议的事情或者处理DataGridView.CellContentClick http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellcontentclick.aspx事件测试按钮是否应该处于活动状态,如果不是则吞掉事件。

从上面的链接:

该属性指示单元格是否处于row or a column和 其 Visible 属性设置为 false。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

根据某些匹配隐藏某些按钮 的相关文章

随机推荐