Treeview select highlight problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HeavyD
    New Member
    • Mar 2007
    • 3

    Treeview select highlight problem

    I am populating a treeview in C# from a SQL Server 2005 database.
    Table tree( id int, parent_id int, name varchar(50).

    The treeview is populated succesfully and when I select a node it is highlited. But if the nodename for example is 5 characters long the highlite is much longer. I think the treeview takes the width from the database table because I have already changed the varchar(50) to varschar(20) and the highlight width is smaller then, but it is still a fixed width.

    What must I do so that the hightlighting is as long as the actual length of a nodename?
  • WebDunce
    New Member
    • Mar 2007
    • 15

    #2
    Hi,

    is it possible that something has added spaces to the ends of the data?

    for instance, when you see "John"...do es the computer see "John" followed by several space characters?

    try iterating thru the data (or the tree nodes)...and call the trim method

    ex:
    myDataString.Tr im() ... or ... myTreeNode.Text .Trim()

    that will remove all white space from the front and back of the tree node's text. if you still have the problem after this...then extra space characters is not the issue.

    Comment

    • WebDunce
      New Member
      • Mar 2007
      • 15

      #3
      ....here is what may be the culprit...what the ANSI-PADDING option was set to when the data table was created...

      from a page at microsoft's website:
      "The varchar data type is a variable-length data type. Values shorter than the size of the column are not right-padded to the size of the column. If the ANSI_PADDING option was set to OFF when the column was created, any trailing blanks are truncated from character values stored in the column. If ANSI_PADDING was set ON when the column was created, trailing blanks are not truncated."

      keep in mind i've never worked with sql...so i could be way off base here.

      but if this is the case...seems like there ought to be a way to fix the data before you add it to the treeview.

      Comment

      • HeavyD
        New Member
        • Mar 2007
        • 3

        #4
        Thank you for your help.

        ANSI padding off or the trim() method when ANSI padding is on does the trick.
        What is the best setting for ANSI padding. Default it was on but isn't off better for performance?

        Comment

        • WebDunce
          New Member
          • Mar 2007
          • 15

          #5
          Originally posted by HeavyD
          Thank you for your help.

          ANSI padding off or the trim() method when ANSI padding is on does the trick.
          What is the best setting for ANSI padding. Default it was on but isn't off better for performance?
          hi heavyd,

          i would guess "off" is better...but that's a guess...this is a good question for the SQL SERVER forum.

          --William

          Comment

          Working...