Solved

TreeNode text length

Posted on 2004-08-25
6
1,362 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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