列表视图中指定列的粗体文本不起作用
本文关键字:文本 不起作用 视图 列表 | 更新日期: 2023-09-27 18:37:14
这段代码有什么问题?第 3 个索引列文本不加粗。
foreach (ListViewItem itm in listView1.Items)
{
itm.SubItems[3].Font = new Font(listView1.Font, FontStyle.Bold);
}
这将起作用:
// create temp font from the item, using BOLD
using (Font f = new Font(lv1.Items(0).SubItems(0).Font, FontStyle.Bold))
{
// loop thru all items
foreach (ListViewItem itm in listView1.Items)
{
// tell SubItems not to use Item Style & set the font
itm.UseItemStyleForSubItems = False;
itm.SubItems[3].Font = f;
}
} // dispose of font
除非另有说明,否则默认设置是SubItems
使用与父项相同的字体和颜色。 这是一个项级属性,因此必须为希望任何子项变化的每个项设置该属性。