Solved

Changing the font of subitems in a ListView

Posted on 2006-06-28
8
526 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

911 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

19 Experts available now in Live!

Get 1:1 Help Now