Click here to Skip to main content
16,014,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

Or just a bit simpler. I'm changing color and font based on returned ping values here:

VB
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
 
Share this answer
 
See code below;
VB
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)
 
Share this answer
 
v4
Comments
souvikd 29-Jul-10 14:47pm    
Hi Thanks for replying, may be i m doing some mistake but it doesnt work, please check the code


For Each row As DataRow In DataSt.Tables(0).Rows
mitem = New ListViewItem
mitem.UseItemStyleForSubItems = False

mitem2 = New ListViewItem
mitem2.UseItemStyleForSubItems = False
mitem2.Font = New Font(lvwMain_default.Font, FontStyle.Bold)


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
mitem2.SubItems.Add("Active").ForeColor = Color.Green
ElseIf row.Item("Status") = False Then
mitem2.SubItems.Add("Closed").ForeColor = Color.Red
End If

'Note to OP, see my comment below; create the subitem object and set the color before adding to the subitems collection of the listviewitem.
DaveAuld 29-Jul-10 14:58pm    
create the subitem before adding it to the parent item;
Dim x As ListViewItem.ListViewSubItem
x.Text = "Something"
x.ForeColor = Color.Aqua
item1.SubItems.Add(x)
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900