我有一部分需要更改为常规字体并从跟踪器中删除。我需要它检查行是否是粗体但是它失败了。
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";
}
}
答案 0 :(得分:0)
我认为你需要一些额外的检查:
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
。