[Closed] Treeview.verticalScroll?
Looks like I can’t get or set values for the vertical scroll for a treeView. Is this the case? Would a work around be placing it in a control that I can and then affect the height of the treeView as nodes are added? I want to be able to control the scrolling.
do you have any reason for not setting tv.topnode instead of scrolling vscroll?
Ya I need to to scroll with another scroll bar.
Have you ever wanted to run naked through a thorn bush? Well this project is making me think that would be less painful.
I just slapped both of the controls that I need to work with in ScrollableControls. How ever this means that I need to manage the height of the control inside to set the scroll bar. Is there a way to force the height of a control to always equal the height of it’s contents?
Here is the nightmare to date. Looks just like it was a month ago eh. Well it is a whole lot different under the hood.
there is no easy way to scroll tree view and update its view. but you can do it with c#
/* C#
using System;
using System.Windows.Forms;
public class TreeViewScrollBars
{
private const int SB_HORZ = 0;
private const int SB_VERT = 1;
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int GetScrollPos(IntPtr hWnd, int nBar);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int SetScrollPos(IntPtr hWnd, int nBar, int pos, bool redraw);
private int GetScrollBars(TreeView tv, int nBar) { return GetScrollPos((IntPtr)tv.Handle, nBar); }
private int SetScrollBars(TreeView tv, int nBar, int pos)
{
tv.BeginUpdate();
SetScrollPos((IntPtr)tv.Handle, nBar, pos, true);
tv.EndUpdate();
return GetScrollBars(tv, nBar);
}
public int GetVScrollPos(TreeView tv) { return GetScrollBars(tv, SB_VERT); }
public int SetVScrollPos(TreeView tv, int pos) { return SetScrollBars(tv, SB_VERT, pos); }
public int GetHScrollPos(TreeView tv) { return GetScrollBars(tv, SB_HORZ); }
public int SetHScrollPos(TreeView tv, int pos) { return SetScrollBars(tv, SB_HORZ, pos); }
}
*/
fn treeViewScroll =
(
source = ""
source += "using System;
"
source += "using System.Windows.Forms;
"
source += "public class TreeViewScrollBars
"
source += "{
"
source += " private const int SB_HORZ = 0;
"
source += " private const int SB_VERT = 1;
"
source += " [System.Runtime.InteropServices.DllImport(\"user32.dll\")]
"
source += " private static extern int GetScrollPos(IntPtr hWnd, int nBar);
"
source += " [System.Runtime.InteropServices.DllImport(\"user32.dll\")]
"
source += " private static extern int SetScrollPos(IntPtr hWnd, int nBar, int pos, bool redraw);
"
source += " private int GetScrollBars(TreeView tv, int nBar) { return GetScrollPos((IntPtr)tv.Handle, nBar); }
"
source += " private int SetScrollBars(TreeView tv, int nBar, int pos)
"
source += " {
"
source += " tv.BeginUpdate();
"
source += " SetScrollPos((IntPtr)tv.Handle, nBar, pos, true);
"
source += " tv.EndUpdate();
"
source += " return GetScrollBars(tv, nBar);
"
source += " }
"
source += " public int GetVScrollPos(TreeView tv) { return GetScrollBars(tv, SB_VERT); }
"
source += " public int SetVScrollPos(TreeView tv, int pos) { return SetScrollBars(tv, SB_VERT, pos); }
"
source += " public int GetHScrollPos(TreeView tv) { return GetScrollBars(tv, SB_HORZ); }
"
source += " public int SetHScrollPos(TreeView tv, int pos) { return SetScrollBars(tv, SB_HORZ, pos); }
"
source += "}
"
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.Add("System.dll");
compilerParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
compilerParams.GenerateInMemory = on
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
compilerResults.CompiledAssembly.CreateINstance "TreeViewScrollBars"
)
scr = treeViewScroll()
you will get methods:
showmethods scr
.<System.Boolean>Equals <System.Object>obj
.[static]<System.Boolean>Equals <System.Object>objA <System.Object>objB
.<System.Int32>GetHashCode()
[color=yellow].<System.Int32>GetHScrollPos <System.Windows.Forms.TreeView>tv
.<System.Type>GetType()
.<System.Int32>GetVScrollPos <System.Windows.Forms.TreeView>tv
.[static]<System.Boolean>ReferenceEquals <System.Object>objA <System.Object>objB
.<System.Int32>SetHScrollPos <System.Windows.Forms.TreeView>tv <System.Int32>pos
.<System.Int32>SetVScrollPos <System.Windows.Forms.TreeView>tv <System.Int32>pos
.<System.String>ToString()[/color]
Thanks Denis !
This c# compile in maxscript is just insane… I see there’s a VB namespace too… just not enough time in the day to explore the possibilities!
I needed the same thing for a ListView… just change four characters and voila!
Thanks again!
I’m surprised because my code shouldn’t work for ListView.
BeginUpdate >…> EndUpdate for ListView resets a scrollbar’s position.
How do you update ListView?
ahhh. You are correct… I only need to read the position of the Hscroll bar so I’d know which column was being clicked on… setting the scrollbar positions has no effect as you expected…
I thought the one of the main points of .net was API consistency… nice to see these work diffferently… :-\
That only updates when you click the column header… it should be ColumnHeaderClick Event, clicking on an object in list does not fire this event…
This usage was a conversion of something I didn’t write from the old ActiveX listview, I probably should have went to a grid controller, but didn’t want to get that involved with getting this script into 2009 x64.
Thanks for your thoughts…
I’ve been jumping in and out of so many GUI API’s the past two years, (Adobe, Andriod, wxPython, .net) , it’s become impossible for me to keep it all straight…
on any click event for listview you can get item and its subitem.
(all that you need to know is the mouse position)
item = lv.GetItemAt arg.x arg.y
sub = item.getSubItemAt arg.x arg.y