• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 551
  • Last Modified:

Changing the font of subitems in a ListView

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?
0
kiranboi
Asked:
kiranboi
  • 4
  • 4
1 Solution
 
Fernando SotoCommented:
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)

Fernando
0
 
kiranboiAuthor Commented:
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)
0
 
Fernando SotoCommented:
Try it this way

    MyItem.SubItems.Add("null").Font = New Font(lstvwColumns.Font, lstvwColumns.FontStyle Or FontStyle.Italic)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kiranboiAuthor Commented:
nope, its still not showing as italic
0
 
Fernando SotoCommented:
Post your code please.
0
 
kiranboiAuthor Commented:
Public Sub PopulateDataset()
        If ImportFilePath = "" Or SheetName = "" Then
            MsgBox("Please Select a File to Import", MsgBoxStyle.Exclamation, "File Error")
            Exit Sub
        End If
        lstvwColumns.Clear()
        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)
        MyConnection.Open()
        MyDataset = New System.Data.DataSet
        MyAdapter.Fill(MyDataset)
        MyConnection.Close()
        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)
        Next
        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
                Try
                    If MyRow(ColumnNumber) Is System.DBNull.Value Then
                        MyItem.SubItems.Add("null").Font = New Font(lstvwColumns.Font, lstvwColumns.Font.Style Or FontStyle.Italic)
                    Else
                        MyItem.SubItems.Add(MyRow(ColumnNumber))
                    End If
                    ColumnNumber = ColumnNumber + 1
                Catch
                    Exit For
                End Try
            Next
            ColumnNumber = 1
            lstvwColumns.Items.Add(MyItem)
        Next
    End Sub
0
 
Fernando SotoCommented:
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.Add("null")
        MyItem.SubItems(0).Font = New Font(MyItem.Font, MyItem.Font.Style Or FontStyle.Italic)
0
 
kiranboiAuthor Commented:
ahhh i see. well i can use that for the whole row later on in my project too. Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now