【问题标题】:Bold text for specified column from listview not working列表视图中指定列的粗体文本不起作用
【发布时间】:2015-01-10 22:29:26
【问题描述】:

这段代码有什么问题?第 3 个索引列文本未加粗。

foreach (ListViewItem itm in listView1.Items)
{
    itm.SubItems[3].Font = new Font(listView1.Font, FontStyle.Bold);
}

【问题讨论】:

  • 第 4 列是否加粗了?
  • 不,没有。只有当我设置itm.Font = new Font(listView1.Font, FontStyle.Bold); 时,所有行才会加粗。但指定的列不起作用。

标签: c# winforms visual-studio-2010


【解决方案1】:

这将起作用:

// 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 使用与父项相同的字体和颜色。这是一个项目级属性,因此必须为 每个 项目设置它,您希望任何子项目发生变化。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多