[Closed] DotNet Listview problem
I’m studying Listview of DotNet.
When I run the script, the name of geometry in file is registered on the Listview.
What I want to do is that when I select few items in the Listview, I want them to be deleted or selected. What should I do to get the array of the selected items?
try(destroydialog ListViewTest)catch()
rollout ListViewTest "Listview Test" width:424 height:255
(
dotNetControl lv "system.windows.forms.listView" height:200 FullRowSelect:true GridLines:true MultiSelect:true
button selBTN "Do It !!" pos:[8,216] width:60 height:30
fn initLv theLv=
(
theLv.view=(dotNetClass "system.windows.forms.view").details
theLv.FullRowSelect=true
theLv.GridLines=true
theLv.MultiSelect=true
)
fn addColumns theLv columnsAr=
(
w=(theLv.width/columnsAr.count)-1
for x in columnsAr do
(
theLv.columns.add x w
)
)
fn getAllObjList theLv =
(
rows=#()
geomArray =#()
for ii in geometry do append geomArray ii.name
for iii in geomArray do
(
li=dotNetObject "System.Windows.Forms.ListViewItem" iii
li.subitems.add ((classOf iii) as string)
append rows li
)
theLv.items.addRange rows
)
on ListViewTest open do
(
initLv lv
addColumns lv #("Objects")
getAllObjList lv
)
on ShootingBTN pressed do
(
testArray = lv.Focus()
print (lv.Focus())
)
on selBTN pressed do
()
)
createdialog ListViewTest ListViewTest.width ListViewTest.height
First, this might be of some help.
http://paulneale.com/tutorials/dotNet/listView/dotNetListView.htm
Next when deleting objects from an array always do it backwards like for i = theArray.count to 1 by -1 do.
Also note that Max arrays are 1 based and dotNet are 0 based so the first object in your lise is 0 and in Max it is 1.
What I suggest is collecting all the objects that you want to display into an array and then showing the contents of that array in the list. When you select something in the list you can find out which item it is in the list and then do what ever you want to the same indexed item in the array +1
Does that help, or an I rambling, it is still early here.
[left]Thank you Pen. I am studying with your tutorial. I know about the difference between max and Dotnet array. [/left]
[left]What I’d like to know is which properties(or fuctions) in Dotnet work as <listbox>.selected or <listbox>.selection in Max.[/left]
[left]and in your tutorial [/left]
[left]
[/left]
[left][size=2]on lv mouseDown arg do[/left]
(
clearListener()
showProperties arg
hit=(lv.HitTest (dotNetObject "System.Drawing.Point" arg.x arg.y))[/size]
[left][size=2][/left]
[/size]
[left]And how can I replace “arg” with the diffrent thing? I thought “lv.item.x “would work but it didn’t. :-([/left]
Arg returns the arguments from the event, call it what ever you want. arg.location is the same as doing (dotNetObject “system.drawing.point” arg.x arg.y) and returns the point at which you a clicking. Then using lv.hitTest and the drawing point you can get the object that you have clicked on. This is the item that you selected. It has properties and you need to check what those are. hit.item.text gets the text in the first column that you clicked on and the subItems get you an array of the columns to the right of it.
If you are trying to make dotNet ListView work like a max script listBox your out of luck, they are two different beasts.
Just worked on this subject myself and I actually don’t beleive you need to “hack” you way to the item.
Tried this and it works just fine :
– for single select conditions :
on lv click do
(
print lv.SelectedItems.item[0].text
)
– for multi select conditions :
on lv click do
(
for i = 1 to lv.SelectedItems.count do (print lv.SelectedItems.item[i-1].text)
)
Access to subitems can be done with xxxx.Subitems
If I missed something, please tell me, but this seems a lot easier.
Tom
Yes this is perfectly valid as well. I think that I have used this in the past to some where. What I showed how ever is not a hack, it is a way to get a node based on where your mouse is and has more uses as you could determine what is under the mouse before a click has taken place. What you have there works great for just getting the selected items and your right, it is a bit easier.
I wrote a script below to select the selected items in the listview when I click the button. But it didn’t work.
on selBTN pressed do
(
TempArray = #()
for i = 1 to lv.SelectedItems.count do
(
if (matchpattern geometry[i].name pattern:(lv.SelectedItems.item[i-1].text)) do
(append TempArray geometry[i])
)
select Temparray
)
I wouldn’t go down that road. You shouldn’t be using the names of the list items to select the objects when you already have them.
So, have an array of all the objects that you are going to place in the list, when the fifth item in the list is selected select the fifth item in the objects array. Remember that dot net is 0 based and Max is 1 based so add one to the integer.
Another way is to store the object that you populated the list with in the .tag property of the listItem. You will need to use dotNetMxsValue theObj to place the object reference in a container that can be placed in the tag property. When the item is selected access the .tag.value property and you will have the object that you can select.
Also I think you can store the object variable directly IN a dotNET item if I remember correctly. I did it in a tree view where every tree item had the node variable as part of the treeview item as some sort of metadata… can’t remember exactly how now though.
In that case it was like item.data = $node
thatoneguy, to do that you use the .tag property of the listItem and you need to use dotNetMxsValue to wrap the object so that it can be stored. You would then acces it like
listItem.tag.value
So…
--Adds rows of data to the listView
fn populateList theLv=
(
rows=#() --Empty array to collect rows of data
for x in objects do --Loop through all the objects in the scene.
(
li=dotNetObject "System.Windows.Forms.ListViewItem" x.name --Create a listViewItem object and name it.
li.tag=dotNetMxsValue x --This is the new line added to my tutorial
append rows li --Added the listViewItem to the rows array
)
theLv.items.addRange rows --Add the array of rows to the listView control.
)