[英]Make font of some rows in a datagridview bold
我只是想強制我的 datagridview 中某些行的字體樣式為粗體,但我似乎無法讓它工作。 我不知道我在哪里出錯了,這似乎是一件簡單的事情,不應該引起任何問題。 我什至放了一個消息框進行調試,這樣我就知道程序正在進入 if 語句。
是否需要設置一個屬性以允許行字體格式或其他內容?
任何幫助表示贊賞,謝謝。
代碼:
//apply row formatting
foreach (DataGridViewRow row in dgvTasks.Rows)
{
//get title of current row
string rowTitle = row.Cells["#"].Value.ToString();
//check if title is digit
if (rowTitle.All(char.IsDigit))
{
row.DefaultCellStyle.Font = new Font("Arial", 15.0F, FontStyle.Bold, GraphicsUnit.Pixel);
MessageBox.Show("test");
}
}
dgvTasks.Rows[0].DefaultCellStyle.Font = new Font("Arial", 15, FontStyle.Bold);
這是一個功能齊全的代碼片段,可用於更改 dataGridView 特定行的字體。
我認為您的 if() 循環或您放入代碼的事件存在問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.