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