当添加到DataGridView c#时,是否可以将行默认设置为不可见?
本文关键字:设置 默认 DataGridView 是否 添加 | 更新日期: 2023-09-27 18:11:01
根据标题,是否可以在添加行时默认设置DataGridView行为visible = false
?
//I am adding rows using the following method..
...
dgvNOPDocs.Rows.Add("Stuff", "MoreStuff");
...
是否有一个DataGridView设置或单元格样式使我们能够做到这一点?
谢谢。
通过这种方式,您可以选择row
可见或不可见,同时添加到DataGridView
:
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#)。
尝试处理栅格的RowsAdded
事件并在那里隐藏新行
public Form1()
{
InitializeComponent();
// attach handler
dgvNOPDocs.RowsAdded += GridOnRowsAdded;
// test
dgvNOPDocs.Rows.Add("Stuff");
dgvNOPDocs.RowCount = 3;
}
private void GridOnRowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
// hide rows
for (int i = e.RowIndex; i < e.RowIndex + e.RowCount; i++)
{
if (dgvNOPDocs.Rows[i].IsNewRow == false)
dgvNOPDocs.Rows[i].Visible = false;
}
}