列表视图中指定列的粗体文本不起作用 [英] Bold text for specified column from listview not working
本文介绍了列表视图中指定列的粗体文本不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这段代码有什么问题?第 3 个索引列文本未加粗.
What is wrong with this code? The 3rd index column text is not made bold.
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
使用与父项相同的字体和颜色.这是一个项目级别的属性,因此必须为每个 项目设置它,其中您希望任何子项目发生变化.
Unless you say otherwise, the default is that SubItems
use the same font and color as the parent Item. This is an item-level property, so it has to be set for each item where you want any of the subitems to vary.
这篇关于列表视图中指定列的粗体文本不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文