Solved

Changing the font of subitems in a ListView

Posted on 2006-06-28
8
531 Views
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?
0
Comment
Question by:kiranboi
[X]
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
8 Comments
 
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)

Fernando
0
 

Author Comment

by:kiranboi
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)
0
 
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)
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!

 

Author Comment

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

Expert Comment

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

Author Comment

by:kiranboi
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
        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
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 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.Add("null")
        MyItem.SubItems(0).Font = New Font(MyItem.Font, MyItem.Font.Style Or FontStyle.Italic)
0
 

Author Comment

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

Featured Post

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!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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