Skip to main content
 首页 » 编程设计

c#之添加到DataGridView C#时是否可以将行设置为默认不可见

2024年02月05日8mayingbao

如标题,是否可以在添加行时将 DataGridView 行默认设置为 visible = false?

//I am adding rows using the following method.. 
... 
dgvNOPDocs.Rows.Add("Stuff", "MoreStuff"); 
... 

是否有 DataGridView 设置或单元格样式使我们能够做到这一点?

谢谢。

请您参考如下方法:

通过这种方式,您可以选择在添加到 DataGridView 时是否显示 row :

DataGridViewRow row = new DataGridViewRow(); //create new row 
row.CreateCells(dgvNOPDocs);   //create cells based on dgv columns 
row.SetValues({"Stuff", "MoreStuff"});  //set values (assuming there is only two columns in Your dgv 
if (some condition why row would be invisible) { row.Visible = false; } 
dgvNOPDocs.Rows.Add(row);  //adding new row into dgv 

我希望这会对您有所帮助(我也希望如此,我正确地从 vb.net 转换为 C#)。