PDA

View Full Version : Treeview.verticalScroll?


PEN
09-16-2009, 08:05 PM
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.

denisT
09-16-2009, 08:32 PM
do you have any reason for not setting tv.topnode instead of scrolling vscroll?

PEN
09-16-2009, 08:45 PM
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?

PEN
09-16-2009, 09:34 PM
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.

http://www.paulneale.com/temp/scripts/composer05.jpg

denisT
09-17-2009, 08:21 PM
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;\n"
source += "using System.Windows.Forms;\n"
source += "public class TreeViewScrollBars\n"
source += "{\n"
source += " private const int SB_HORZ = 0;\n"
source += " private const int SB_VERT = 1;\n"
source += " [System.Runtime.InteropServices.DllImport(\"user32.dll\")]\n"
source += " private static extern int GetScrollPos(IntPtr hWnd, int nBar);\n"
source += " [System.Runtime.InteropServices.DllImport(\"user32.dll\")]\n"
source += " private static extern int SetScrollPos(IntPtr hWnd, int nBar, int pos, bool redraw);\n"
source += "\tprivate int GetScrollBars(TreeView tv, int nBar) { return GetScrollPos((IntPtr)tv.Handle, nBar); }\n"
source += " private int SetScrollBars(TreeView tv, int nBar, int pos)\n"
source += " {\n"
source += " tv.BeginUpdate();\n"
source += " SetScrollPos((IntPtr)tv.Handle, nBar, pos, true);\n"
source += " tv.EndUpdate();\n"
source += " return GetScrollBars(tv, nBar);\n"
source += " }\n"
source += " public int GetVScrollPos(TreeView tv) { return GetScrollBars(tv, SB_VERT); }\n"
source += " public int SetVScrollPos(TreeView tv, int pos) { return SetScrollBars(tv, SB_VERT, pos); }\n"
source += " public int GetHScrollPos(TreeView tv) { return GetScrollBars(tv, SB_HORZ); }\n"
source += " public int SetHScrollPos(TreeView tv, int pos) { return SetScrollBars(tv, SB_HORZ, pos); }\n"
source += "}\n"

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()
.<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()

Kramsurfer
09-21-2009, 07:06 PM
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!

denisT
09-21-2009, 09:08 PM
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?

Kramsurfer
09-21-2009, 09:28 PM
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... :-\

denisT
09-21-2009, 09:46 PM
I only need to read the position of the Hscroll bar so I'd know which column was being clicked on...


is not easer to use ColumnClick event?

Kramsurfer
09-21-2009, 10:41 PM
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...

denisT
09-21-2009, 10:51 PM
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

Kramsurfer
09-21-2009, 11:12 PM
yup.. but that mouse position is relative to the control..

So if you scroll horizontally you get a Mouse X value relative to the control's position, one then needs to add the scroll position... which works perfect..

CGTalk Moderation
09-21-2009, 11:12 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.