检查所选的dataGridView行是否为粗体
本文关键字:是否 dataGridView 检查 | 更新日期: 2023-09-27 18:11:32
我有一段需要更改为常规字体并从跟踪器中删除。我需要它检查行是否粗体,但它失败了。
private void clientDataGridView_SelectionChanged(object sender, EventArgs e)
{
foreach (DataGridViewRow row in clientDataGridView.SelectedRows)
{
if (row.DefaultCellStyle.Font.Style == FontStyle.Bold)
{
row.DefaultCellStyle.Font = new Font(DefaultFont, FontStyle.Regular);
new_tracker --;
}
idtxt.Text = row.Cells[0].Value.ToString();
emailtxt.Text = row.Cells[1].Value.ToString();
nametxt.Text = row.Cells[2].Value.ToString();
packagetxt.Text = row.Cells[3].Value.ToString();
notificationToolStripStatusLabel.Text = "0 new notifications";
}
}
我认为你还需要一些额外的检查:
if (row == null) result = "row is null";
else if (!row.HasDefaultCellStyle) result = "no row style"; // this helps!
else if (row.DefaultCellStyle.Font == null) result = "no font"; // may work without
else if (row.DefaultCellStyle.Font.Bold) result = "bold";
我发现这对于行是有效的,在这里我实际上设置了HasDefaultCellStyle
.