Notifications
Clear all

[Closed] listview hittest on right click?

I’m hoping someone can help point me in the right direction please. I’m a fairly competent with maxscript, but I’m pretty new to using dotnet and I’m trying to wrap my head around it. I’m basically trying to write my own layer manager as a way of learning dotnet.

I’ve managed to create a listview that lists all the layers in the scene and I’m able to toggle the layers on and off by clicking on the name. Simple stuff so far. I’ve also been able to create a popupmenu when I right click. However, this is where I’m now stuck.

When a right click is performed is it also possible to do a hittest for where the mouse was at when I right clicked? If this is possible can someone explain (or show) how this is done? I’d like to right click on a layer name and have an rcmenu pop up that will allow me to add selected scene objects to the corresponding layer that I right clicked over.

Also…By default when you select an item in the listview the row is highlighted. I would like to not have anything be highlighted when I select it in the listview. I’m changing the background color of the row so that I can visibly see if a layer is toggled on or off. I can’t figure out if disabling selection highlighting is possible or how to do it though.

Thanks for your help!

Tim J

11 Replies

Hey Tim,

Yep this is possible to do with a few lines of code. This is taken from the Maxscript help file ‘Converting ActiveX Treeview Control to DotNet Treeview Control’


on tv Click arg do
(
--First get theTreeView node below the mouse cursor --The arg argument has properties .x and .y with the current pos. --Use showProperties arg to see what is available... --We use the TreeView method GetNodeAt to see what was clicked:
hitNode = tv.GetNodeAt (dotNetObject "System.Drawing.Point" arg.x arg.y)
)

The listview has a similar method to the treeview by using getItemAt, which will allow you to obtain the layer item
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview_methods.aspx

Regarding your second question, you will probably have to handle the drawing yourself to override the default selection and focus behaviour. This example will help you go in the right direction.
http://forums.cgsociety.org/showpost.php?p=5482749&postcount=23

If you have any more questions, ask away. I’ve spent a lot of time looking into this

I’m not sure what I’m doing wrong. That very simple line of code is giving me an error.

on lv Click arg do
(
hit = lv.GetItemAt (dotNetObject "System.Drawing.Point" arg.x arg.y)
--hit = lv.HitTest (dotNetObject "System.Drawing.Point" arg.x arg.y)
)

as soon as I click anywhere in my listview I get the following error…Using either of the lines in the code above.

“–Unknown property: ‘x’ in dotNetObject:System.EventArgs”

However, if I go with this code instead I don’t get an error…

on lv mouseDown arg do
(
hit = lv.HitTest (dotNetObject "System.Drawing.Point" arg.x arg.y)
)

Any idea why the first way crashes and the second works just fine?

Bummer that there isn’t some toggle to just disable selection highlighting…but I can probably code my way around that.

Thanks for your help!

Tim J

Hey Tim,

The reason getItemAt errors is because the method wants two integer values rather than a dotNet point class.

It looks like there are two different methods available:


on lv mouseDown arg do (
	print (lv.getItemAt arg.x arg.y)
	hitInfo = (lv.hitTest arg.location)
	print hitInfo.item
        print hitInfo.subItem
)

HitInfo also has a subItem property, so that one may be more flexible to use than getItemAt.

Cheers
Tim

Whoops double post, chrome just went whacky when I pressed submit

Ah Ha! I get it now.

So what is the difference between using…

on lv click arg do

and

on lv mousedown arg do

is one more flexible than the other?

Tim J

[ul]
[li]Mousedown fires when the mouse is pressed down over an item.
[/li][li]Mouseup fires when the mouse is released over an item.
[/li][li]Click is fired when a mousedown and mouseup occurs over an item (so if a user presses the mousedown, then moves the mouse and releases, click will not fire).
[/li][/ul]

Different events are good for different functions. If you open up the normal layer manager, you’ll notice that the layer properties change on a mousedown, which makes the UI seem quite fast in comparison to a mouseup event that could have been used. A good place to use “click” is on a button, where sometimes you may press down on it, then realise you dont want to complete the click and you can move the mouse away – not firing the click function.

Cheers
Tim

btw…I solved my selection highlighting issue by going with

on lv mouseup arg do

and then refreshing my UI at the end. Seems to do the trick.

Thanks Tim! This info is really helpful and is making more sense now. I really appreciate you taking the time to explain this stuff.

No problem, glad I can help. Next challenge – add drag and drop support

Page 1 / 2