2016-10-05 56 views
0

我有一段需要更改爲常規字體並從跟蹤器中刪除。我需要檢查該行是否是粗體,但是是否失敗。檢查所選的dataGridView行是否爲粗體

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

我想你需要一些額外的檢查:

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工作。

相關問題