PDA

View Full Version : ListBoxes



spencer.67965
2004-06-17, 03:59 PM
I am trying to populate text from one listBox to another. I have successfully accomplished this while the multiselect mode is set to 0; however, I would like to select more than one item at a time. When I tried to do is it crashed. Does anyone know if I can use (lisBox.text) while multiselect is set to 1 or 2? . . . is there another way to do this?


Spencer

Ed Jobe
2004-06-17, 04:36 PM
What crashed? Did you get any error msg's?

spencer.67965
2004-06-17, 05:02 PM
It was setting my variable to "" then (crashing) I just switched it back again and apparently it doesent crash it just dosent work, apparently when you have more than one selected the listbox.text dosent work. Hope that helped. Let me know if it didn't.

Thanks

Ed Jobe
2004-06-17, 05:13 PM
You still havn't defined "crashing". Does acad crash, windows, the procedure? What, how? error msgs? Please be specific.

spencer.67965
2004-06-17, 05:25 PM
No error message no crash. It simply dosen't do anything. By changing the MultiSelect Property to 2 from 0 it stops populating the selected text in ListBox1 to ListBox2.

Hope that helps.

Thanks again

Ed Jobe
2004-06-17, 06:46 PM
Ok, now that that's settled, here's something from the help on the MultiSelect property:

Remarks

When the MultiSelect property is set to Extended or Simple, you must use the list box's Selected property to determine the selected items. Also, the Value property of the control is always Null.

spencer.67965
2004-06-17, 07:45 PM
Thanks for the help, I will give it a go and see what I come up with.

Ed Jobe
2004-06-17, 07:52 PM
Note that the Selected property doesn't give you the values either. You have to iterate through the list box's List collection and examine the Selected property of each item.

jwanstaett
2004-06-17, 08:17 PM
try some thing like this
the name of the two listbox are
listbox1
listbox2

'add this if the need to clear listbox2 first
listbox2.clear

'note: I go from last item to first item so the remove item works

For i = listbox1.ListCount - 1 To 0 Step -1
If listbox1.Selected(i) Then
listbox2.add listbox1.list(i)
'add this list if the need to remove the item form listbox1
listbox1.Remove i
End If
Next

while we are talking listboxs dose VBa let you sort the item in listboxs
I know tha VB dose
if so I have not found out how to set the sort for a listbox
But I use a AcadDictionary to get the listBox sorted

spencer.67965
2004-06-17, 08:47 PM
That worked perfect. I modified it just a bit to make it work with VBA so here is the code.

THANK YOU!


Dim I As Long

For I = ListBox1.ListCount - 1 To 0 Step -1
If ListBox1.Selected(I) Then
ListBox2.AddItem ListBox1.List(I)
ListBox1.RemoveItem (I)
End If
Next

Ed Jobe
2004-06-17, 08:59 PM
No, you have to use one of the widely available sort algorithms, e.g. Bubble Sort. Then populate the List.

PellaCAD
2006-12-31, 07:57 PM
Sure could use some help figuring out how to find and use these sort routines...

Perhaps there are some routines you could send to us?? It would REALLY be appreciated!

Pete

jwanstaett
2007-01-09, 02:10 PM
you need to sort the list box as you add item to it. when you add a item loop Thur to list box and compare to value you are adding to the items in the list. The fist time it is > then the item in the list add it at that index.