Solved

Changing the font of subitems in a ListView

Posted on 2006-06-28
8
525 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
  • 4
  • 4
8 Comments
 
LVL 62

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 62

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
 

Author Comment

by:kiranboi
ID: 17001814
nope, its still not showing as italic
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 62

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 62

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now