c# - ListView 中指定列的粗体文本不起作用

标签 c# winforms visual-studio-2010

这段代码有什么问题?第 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 使用与父项相同的字体和颜色。这是项目级属性,因此必须为每个 项目设置它,您希望其中的任何子项目发生变化。

关于c# - ListView 中指定列的粗体文本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27881880/

相关文章:

c# - 计算 Windows 文件夹大小的最快方法是什么?

c# - 数组中有多少元素不为空?

c# - 验证显示 HDCP 合规性(强制 HDCP 输出,如果 HDCP 不可用则禁用输出)

c# - 用于数字的正确数据类型是什么

c# - WiX - 安装先决条件和第 3 方应用程序

c# - 如何强制在 chrome android 上内联打开 pdf 文档?

c# - 使用 LINQ "everywhere"时的性能问题?

c# - 数据库已经存在。使用 CreateDatabase() 选择不同的名称

windows - 具有可见表单的 Excel-Addin

c++ - 如何在 Visual Studio 2010 中禁用返回值优化?