Changing the font of subitems in a ListView

Posted on 2006-06-28
Medium Priority
Last Modified: 2013-12-03
I have a ListView in my app with a number of columns (details view). I am trying to change certain cells to have an italic font but i keep getting an error saying that it is a read only property. What am i doing wrong?
Question by:kiranboi
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
LVL 63

Expert Comment

by:Fernando Soto
ID: 17001645
Hi kiranbo;

In Visual Studio .Net Fonts are read only. So to change the font you need to create a font and assign that font to the object. Try something like this.

        ListView1.Items.Item(2).Font = New Font(ListView1.Items.Item(2).Font, _
            ListView1.Items.Item(2).Font.Style Or FontStyle.Italic)


Author Comment

ID: 17001733
ive changed it to this as the listview is the standard font that i would like italicising for this object but its still not working

 MyItem.SubItems.Add("null").Font = New Font(lstvwColumns.Font, FontStyle.Italic)
LVL 63

Expert Comment

by:Fernando Soto
ID: 17001798
Try it this way

    MyItem.SubItems.Add("null").Font = New Font(lstvwColumns.Font, lstvwColumns.FontStyle Or FontStyle.Italic)
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 17001814
nope, its still not showing as italic
LVL 63

Expert Comment

by:Fernando Soto
ID: 17001837
Post your code please.

Author Comment

ID: 17001872
Public Sub PopulateDataset()
        If ImportFilePath = "" Or SheetName = "" Then
            MsgBox("Please Select a File to Import", MsgBoxStyle.Exclamation, "File Error")
            Exit Sub
        End If
        MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; " & "data source=" & ImportFilePath & "; " & "Extended Properties=Excel 8.0;")
        MyAdapter = New System.Data.OleDb.OleDbDataAdapter("select * from [" & SheetName & "$]", MyConnection)
        MyDataset = New System.Data.DataSet
        DatasetRows = MyDataset.Tables(0).Rows.Count()
        DatasetColumns = MyDataset.Tables(0).Columns.Count()
        For Each MyDataColumn As DataColumn In MyDataset.Tables(0).Columns
            lstvwColumns.Columns.Add(MyDataColumn.ColumnName, 80, HorizontalAlignment.Left)
        Dim MyRow As DataRow
        Dim MyItem As ListViewItem
        Dim i As Integer
        Dim ColumnNumber As Integer = 1
        For Each MyRow In MyDataset.Tables(0).Rows
            MyItem = New ListViewItem(MyRow(0).ToString)
            For i = 0 To DatasetColumns
                    If MyRow(ColumnNumber) Is System.DBNull.Value Then
                        MyItem.SubItems.Add("null").Font = New Font(lstvwColumns.Font, lstvwColumns.Font.Style Or FontStyle.Italic)
                    End If
                    ColumnNumber = ColumnNumber + 1
                    Exit For
                End Try
            ColumnNumber = 1
    End Sub
LVL 63

Accepted Solution

Fernando Soto earned 2000 total points
ID: 17002387
Hi kiranboi;

I have been only able to change the font of the 1 whole line in the ListView control. I do not know if you can change an individual column or not. Here is how to change the whole line.

        MyItem.SubItems(0).Font = New Font(MyItem.Font, MyItem.Font.Style Or FontStyle.Italic)

Author Comment

ID: 17002437
ahhh i see. well i can use that for the whole row later on in my project too. Thanks

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question