我正在尝试将ListView项或ListView中的特定列设置为粗体。这是我的代码,我知道它不对,所以我要求帮助才能使其正常工作。
Do While reader.Read = True
list = ListView1.Items.Add(reader(3).ToString)
list.SubItems.Add(reader(4).ToString = Font.Bold)
list.SubItems.Add(reader(5).ToString)
list.SubItems.Add(reader(6).ToString)
Loop
答案 0 :(得分:0)
您必须首先创建一个Font,然后将该Font与ListViewItem和/或ListViewSubItem相关联
Dim fnt_Font As Font
Dim lvitm_Item As ListViewItem
' Set Font
fnt_Font = New Font("Calibri", 10, FontStyle.Bold)
Do While reader.Read = True
' Add ListView Item
lvitm_Item = ListView1.Items.Add(reader(3).ToString)
' Add Font
lvitm_Item.Font = fnt_Font
' Add SubItem
lvitm_Item.SubItems.Add(reader(4).ToString)
' Add Font
lvitm_Item.SubItems(1).Font = fnt_Font
' Add SubItem
lvitm_Item.SubItems.Add(reader(5).ToString)
' Add Font
lvitm_Item.SubItems(2).Font = fnt_Font
' Add SubItem
lvitm_Item.SubItems.Add(reader(6).ToString)
' Add Font
lvitm_Item.SubItems(3).Font = fnt_Font
Loop
' Clean Objects
lvitm_Item = Nothing
OR
Dim fnt_Font As Font
Dim lvitm_Item As ListViewItem
Dim lvsbitm_SubItem as ListViewItem.ListViewSubItem
' Set Font
fnt_Font = New Font("Calibri", 10, FontStyle.Bold)
Do While reader.Read = True
' Add ListView Item
lvitm_Item = ListView1.Items.Add(reader(3).ToString)
' Add Font
lvitm_Item.Font = fnt_Font
' Add SubItem
lvsbitm_SubItem = lvitm_Item.SubItems.Add(reader(4).ToString)
' Add Font
lvsbitm_SubItem.Font = fnt_Font
' Add SubItem
lvsbitm_SubItem = lvitm_Item.SubItems.Add(reader(5).ToString)
' Add Font
lvsbitm_SubItem.Font = fnt_Font
' Add SubItem
lvsbitm_SubItem = lvitm_Item.SubItems.Add(reader(6).ToString)
' Add Font
lvsbitm_SubItem.Font = fnt_Font
Loop
' Clean Objects
lvsbitm_SubItem = Nothing
lvitm_Item = Nothing
您可以为每个ListViewItem和ListViewSubItem添加不同的Font。
根据您的需要,DataGridView更适合像控件这样的表。
希望有所帮助!