Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

TreeNode text length

Posted on 2004-08-25
6
Medium Priority
?
1,494 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
[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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Accepted Solution

by:
imu79 earned 1000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

722 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