Solved

TreeNode text length

Posted on 2004-08-25
6
1,329 Views
Last Modified: 2013-12-03
I have a TreeView control in which I must display fairly long text strings in the nodes (50-60 character strings).  Although I set the TreeNode's text property to the entire string it is only displaying partial strings (it seems to depend on the font).  With a font size of 9, I am only seeing approximately 37 characters.  With smaller font sizes I get more, but that's not the solution I'm looking for.  Changing the width property of the TreeView itself makes no difference, it seems to be a problem with the individual nodes cutting off the text.  Anyone have a clue?
0
Comment
Question by:PowerBids
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:prakash_prk
ID: 11899977

Can you give the code of the form

prakash
0
 
LVL 3

Expert Comment

by:imu79
ID: 11902060
I didn't have problems setting text of lengths 60-70 chars for standard font size on tree nodes. As Prakash mentioned, it would help if you could post the code.

Imran.
0
 

Author Comment

by:PowerBids
ID: 11904562
Here is a simple example form to illustrate my problem.  In this form I have placed a TreeView and added a single node with a long line of text.  I noticed when I did this that the problem seems to revolve around the setting of the nodefont property.  If I comment out the line where I set the nodefont, the entire line of text displays properly.  But when I set the nodefont property, the last few characters get chopped off:

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TreeView1 = New System.Windows.Forms.TreeView
        Me.SuspendLayout()
        '
        'TreeView1
        '
        Me.TreeView1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.TreeView1.ImageIndex = -1
        Me.TreeView1.Location = New System.Drawing.Point(0, 0)
        Me.TreeView1.Name = "TreeView1"
        Me.TreeView1.SelectedImageIndex = -1
        Me.TreeView1.Size = New System.Drawing.Size(292, 266)
        Me.TreeView1.TabIndex = 0
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.TreeView1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim tvn As TreeNode
        tvn = Me.TreeView1.Nodes.Add("This is a very long line of text to place in a node")
        tvn.NodeFont = New Drawing.Font("Arial", 9, FontStyle.Regular)
    End Sub
End Class
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Accepted Solution

by:
imu79 earned 250 total points
ID: 11904839
Try setting the NodeFont property before adding any nodes to the tree.

Imran.
0
 

Author Comment

by:PowerBids
ID: 11907090
It looks like this is a bug in treeview.  As you suggest Imran, setting the font for the tree overall allows you to display the entire line of text in the desired font.  However, it seems that if you want to have various fonts to display for various nodes, you have to set the treeview font up front to the biggest one you will want to display, and then change fonts for individual nodes as they are added.  If you try to increase a font size of a node to a larger size than the treeview's font, it will clip the text to the length it would display in the treeview's font.
0
 
LVL 3

Expert Comment

by:imu79
ID: 11907240
Indeed that does look like a bug.

here's a discussion that I found while googling for this issue:
http://www.windowsforms.net/Forums/ShowPost.aspx?tabIndex=1&tabId=41&PostID=4595

thought that might of interest to you.

hope it helps resolve your issue (atleast temporarily).

Imran.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Template or Software to write user guide 2 32
visual Basic Net vs c# net 8 56
Spacing between controls 4 17
Close word object 13 21
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

24 Experts available now in Live!

Get 1:1 Help Now