如何在vb.net中的ListView中使特定值变为粗体 [英] How to make a particular value Bold in ListView in vb.net
本文介绍了如何在vb.net中的ListView中使特定值变为粗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使文本以粗体显示,并在列表视图中更改特定列的文本大小,但我无法做到。我已尝试使用以下代码.Thnx。
For Each Row As DataRow In DataSt.Tables(0).Rows
mitem = New ListViewItem
mitem.UseItemStyleForSubItems = False
mitem.Text = row.Item(IssID)'在Lvw中,第一列应为Text
mitem.SubItems.Add(row。 Item(Descrptn))
如果row.Item(Status)= True则
mitem.SubItems.Add(Active)。ForeColor = Color.Green
'需要加粗
mitem.SubItems.Add(Active)。Text = Font.Bold'不起作用
ElseIf row.Item(Status)= False然后
mitem.SubItems.Add(Closed)
mitem.SubItems.Add(Active)。ForeColor = Color.Red
End If
解决方案
请参阅下面的代码;
Dim 项目1 作为 新 ListViewItem
item1.Text = 项目1 BOLD
item1.UseItemStyleForSubItems = False 将此项设置为FALSE以允许更改子项字体。默认情况下为TRUE。
item1.Font = 新字体(ListView1.Font,FontStyle.Bold)
item1.SubItems .Add( Sub Item Normal)
item1.SubItems( 1 )。Font = 新字体(ListView1.Font,FontStyle.Regular)
Dim item2 作为 新 ListViewItem
item2。 Text = Item 2 Normal
item2.UseItemStyleForSubItems = 错误
item2.Font = 新字体(ListView1.Font,FontStyle.Regular)
item2.SubItems.Add ( Sub Item Bold)
item2.SubItems( 1 )。Font = 新字体( ListView1.Font,FontStyle.Bold)
ListView1.Items.Add(item1)
ListView1.Items.Add(item2)
mitem.SubItems.Add(Active)。Text = Font.Bold'不起作用
你只需将Font.Bold的值设置为文本。
参见 MSDN文档 [ ^ ]设置字体
或只是有点简单。我在这里根据返回的ping值更改颜色和字体:
如果 replypingms< LVMainNodesList.Items(i).SubItems( 2 )。文本然后 ' 我们在
LVMainNodesList.Items(i).BackColor = Color.Green
LVMainNodesList.Items(i )。.ForeColor = Color.Black
LVMainNodesList.Items(i).font = 新字体(LVMainNodesList.Font,FontStyle.Regular)
< span class =code-keyword> ElseIf replypingms> (LVMainNodesList.Items(i).SubItems( 2 )。文本* 2 )然后 ' WAY OVER
LVMainNodesList.Items(i ).BackColor = Color.Red
LVMainNodesList.Items(i).ForeColor = Color.WhiteSmoke
' 我想将字体设置为BOLD以引起注意......
LVMainNodesList.Items(i).Font = 新 Font(LVMainNodesList.Font,FontStyle.Bold)
Else ' 我们已经过时了,不要惊慌
LVMainNodesList.Items(i).BackColor = Color.Yellow
LVMainNodesList.Items(i).ForeColor = Color.Black
LVMainNodesList.Items(i).Font = 新字体(LVMainNodesList.Font,FontStyle.Regular)
结束 如果
Hi,
i am trying to make the text appear in bold and to change the text size for a particular colum in a list view, but i am unable to . i have tried with the following code.Thnx .
For Each row As DataRow In DataSt.Tables(0).Rows mitem = New ListViewItem mitem.UseItemStyleForSubItems = False mitem.Text = row.Item("IssID") 'In Lvw the first column should be Text mitem.SubItems.Add(row.Item("Descrptn")) If row.Item("Status") = True Then mitem.SubItems.Add("Active").ForeColor = Color.Green 'Need to make it bold mitem.SubItems.Add("Active").Text = Font.Bold ' doesnt work ElseIf row.Item("Status") = False Then mitem.SubItems.Add("Closed") mitem.SubItems.Add("Active").ForeColor = Color.Red End If
解决方案
See code below;
Dim item1 As New ListViewItem item1.Text = "Item 1 BOLD" item1.UseItemStyleForSubItems = False 'Set this to FALSE to allow changing the subitem font. It is TRUE by default. item1.Font = New Font(ListView1.Font, FontStyle.Bold) item1.SubItems.Add("Sub Item Normal") item1.SubItems(1).Font = New Font(ListView1.Font, FontStyle.Regular) Dim item2 As New ListViewItem item2.Text = "Item 2 Normal" item2.UseItemStyleForSubItems = False item2.Font = New Font(ListView1.Font, FontStyle.Regular) item2.SubItems.Add("Sub Item Bold") item2.SubItems(1).Font = New Font(ListView1.Font, FontStyle.Bold) ListView1.Items.Add(item1) ListView1.Items.Add(item2)
mitem.SubItems.Add("Active").Text = Font.Bold ' doesnt work
you just setting the value of Font.Bold to be the text.
see MSDN documentation[^] to to set the font
Or just a bit simpler. I'm changing color and font based on returned ping values here:
If replypingms < LVMainNodesList.Items(i).SubItems(2).Text Then ' we're under LVMainNodesList.Items(i).BackColor = Color.Green LVMainNodesList.Items(i).ForeColor = Color.Black LVMainNodesList.Items(i).Font = New Font(LVMainNodesList.Font, FontStyle.Regular) ElseIf replypingms > (LVMainNodesList.Items(i).SubItems(2).Text * 2) Then ' WAY OVER LVMainNodesList.Items(i).BackColor = Color.Red LVMainNodesList.Items(i).ForeColor = Color.WhiteSmoke ' I'd like to set the font to BOLD to bring attention to it... LVMainNodesList.Items(i).Font = New Font(LVMainNodesList.Font, FontStyle.Bold) Else ' We're over a litle, don't panic LVMainNodesList.Items(i).BackColor = Color.Yellow LVMainNodesList.Items(i).ForeColor = Color.Black LVMainNodesList.Items(i).Font = New Font(LVMainNodesList.Font, FontStyle.Regular) End If
这篇关于如何在vb.net中的ListView中使特定值变为粗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文