Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!!!
I use treeview, which nodes are different in height. For this, I use function HeiNode that call (if necessary), when I add nodes (function code is shown below). But in this case, if you do scroll to the bottom, the last node will be visible not all and scrolling can not be scroll to the end (it will automatically "jump" a little higher).
If I increase the height of the form - that everything is normal.
Can you please tell how to solve this problem!
In the example below, for simplicity, the height of all nodes increases 5 times.
The main form, where the addition of nodes:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace WindowsFormsApplication1
{
  public partial class Form1 : Form
  {
    My_tree_view mtv = new My_tree_view();
    public Form1()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      
     mtv.Visible = true;
     this.Controls.Add(mtv);
     mtv.BeginUpdate();
     for (int i = 0; i < 20; i++)
     {
       TreeNode tn = new TreeNode("node" + i.ToString());
       tn.Name = "node" + i.ToString();
       mtv.Nodes.Add(tn);

       mtv.HeiNode(tn.Handle.ToInt32());



     }
     mtv.EndUpdate();
  
    }
    

   
  }
}


My treeview:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
  class My_tree_view : System.Windows.Forms.TreeView
  {
    public My_tree_view():base()
    {
    this.Visible = true;
     
      this.Scrollable = true;
      this.DrawMode = TreeViewDrawMode.OwnerDrawAll;
      this.BorderStyle = BorderStyle.Fixed3D;
      this.FullRowSelect = true;
      this.HideSelection = false;
      this.Dock=DockStyle.Fill;
      this.ShowPlusMinus = false;
      this.ShowRootLines = false;
      this.ItemHeight = 17;
    
    }
    [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Auto)]
    public struct TVITEM
    {
      public uint mask;
      public IntPtr hItem;
      public uint state;
      public uint stateMask;
      public IntPtr pszText;
      public int cchTextMax;
      public int iImage;
      public int iSelectedImage;
      public int cChildren;
      public IntPtr lParam;
      public int iIntegral;

    }
    public enum TVIF : int
    {
      TVIF_TEXT = 0x0001,
      TVIF_IMAGE = 0x0002,
      TVIF_PARAM = 0x0004,
      TVIF_STATE = 0x0008,
      TVIF_HANDLE = 0x0010,
      TVIF_SELECTEDIMAGE = 0x0020,
      TVIF_CHILDREN = 0x0040,
      TVIF_INTEGRAL = 0x0080
    }
    public enum TreeViewMessages : int
    {
      TV_FIRST = 0x1100,   // TreeView messages
      TVM_SETITEM = (TV_FIRST + 13),
      TVM_SETITEMHEIGHT = (TV_FIRST + 27)
    }
    public void HeiNode(int hItem)
    {
      if (hItem > 0)
      {
        TVITEM tvi = new TVITEM();
        tvi.mask = (uint)TVIF.TVIF_HANDLE | (uint)TVIF.TVIF_INTEGRAL;
        tvi.hItem = new IntPtr(hItem);
        tvi.stateMask = (uint)TVIF.TVIF_INTEGRAL;
        tvi.state = 0;

        tvi.iIntegral = 5;

        IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(tvi));

        try
        {
          Marshal.StructureToPtr(tvi, ptr, false);
          Message msg = Message.Create(this.Handle, (int)TreeViewMessages.TVM_SETITEM, IntPtr.Zero, ptr);
          DefWndProc(ref msg);
        }
        finally
        {
          Marshal.FreeHGlobal(ptr);
        }
      }
    }
    private void InitializeComponent()
    {
      this.SuspendLayout();
      // 
      // My_tree_view
      // 
       this.ResumeLayout(false);

    }
    
    
    protected override void OnDrawNode(DrawTreeNodeEventArgs e)
    {
      Rectangle rec = e.Bounds;
      e.Graphics.FillRectangle(Brushes.Aqua, rec);
      e.Graphics.DrawRectangle(Pens.Black, rec.X, rec.Y, rec.Width, rec.Height - 2);
      e.Graphics.DrawString(e.Node.Name, new Font("Times", 12f,FontStyle.Bold),Brushes.Black,new PointF(rec.X+10,rec.Y+5));
      base.OnDrawNode(e);
      
    }
    
  }
}


Thanks!)
Posted
Updated 3-Jun-10 2:44am
v4

1 solution

Post your question in a language everyone can understand so that more people can help you. English is the preferred choice.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900