• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1580
  • Last Modified:

TreeNode text length

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
PowerBids
Asked:
PowerBids
  • 3
  • 2
1 Solution
 
prakash_prkCommented:

Can you give the code of the form

prakash
0
 
imu79Commented:
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
 
PowerBidsAuthor Commented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
imu79Commented:
Try setting the NodeFont property before adding any nodes to the tree.

Imran.
0
 
PowerBidsAuthor Commented:
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
 
imu79Commented:
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

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now