[Closed] .NET combobox
Hello,
i need some help with the .NET combobox control. I don’t know how to add items to the list of this control. I’m making a full .NET interface. Here’s an example of a listview i use
lv = dotnetobject "listview"
i = dotnetobject "listviewitem"
i.text = "nice item"
lv.items.add i
So that’s how i add items to a listview, very straightforward. But i can’t do this with a combobox
cmb = dotnetobject "combobox"
cmb.items.add ....
now i don’t know how to add items to this combobox. i can’t find an “comboboxitem” object to add to the combobox. When i try to just add a string i get an error.
Can someone help me to put some strings in this combobox?
Thanks,
Klaas
While this works (and I’m impressed that you’ve gone down this path), you’ll find you can also do
i = lv.items.add "Nice item"
This will add an item, with the text “Nice Item” to the list and return the newly created list view item
So that's how i add items to a listview, very straightforward. But i can't do this with a combobox
cmb = dotnetobject "combobox" cmb.items.add ....
now i don't know how to add items to this combobox. i can't find an "comboboxitem" object to add to the combobox. When i try to just add a string i get an error. Can someone help me to put some strings in this combobox?
So, with our previous discovery in mind (and a quick glance at the docs), you should be able to do:
cmb.items.add "Nice Item"
This will return the index of where the new item
The main differences are, the ListView.Items collection is a ListViewItemCollection, which provides some additional methods for manipulating the collection, where as the ComboBox.Items collection is a standard ObjectCollection, so there methods will differ slightly. Not that any of this is that important…
Hope this helps.
Thanks for helping out. Sadly enough i don’t get it. The tip on the listview is nice. I tend to elaborate on my code, doing it step by step. But the combobox just gives me an error. I’ll show you what i’m doing:
combo = dotnetobject "combobox"
i = combo.items.add "nice item"
This results in: -- Runtime error: No method found which matched argument list
So whereas this method works on a listview or treeview for that matter, my combobox doesn't like it. I thought it's beacuse there isn't some "comboboxItemCollection" where i can set the text or name on such an item. There's just an "objectCollection" (as you've pointed out) and i'm rather clueless about how to make them work for me.
The only way i can add stuff to my combobox is by actually making a “system.object”.
combo = dotnetobject "combobox"
o = dotnetobject "object"
i = combo.items.add o
This results in the index of the item. But i don’t know how to edit these “object” objects.
Could you help me turning this object into something with a string? Or just plainly point me into the right way.
Klaas
You are very close!!
Rather then using an Object, you should be using a string. This will allow the combobox to display text
combo = dotnetobject "combobox"
dnStr = dotnetobject "String" "Have a nice day"
i = combo.items.add dnStr
Shane
As Shane said, you have to create a System.String.
Here is how you can use a .NET ComboBox in a rollout:
rollout dotNetComboBoxTest ".NET ComboBox Test" width:200 height:40
(
dotNetControl comboBox "System.Windows.Forms.ComboBox" pos:[10,8] width:180 height:21
on dotNetComboBoxTest open do
(
comboBox.Items.Add (dotNetObject "System.String" "Text 1")
comboBox.Items.Add (dotNetObject "System.String" "Text 2")
comboBox.SelectedIndex = 0
ComboBoxStyle = dotNetClass "System.Windows.Forms.ComboBoxStyle"
comboBox.DropDownStyle = ComboBoxStyle.DropDownList
)
on comboBox SelectedValueChanged do
(
if comboBox.SelectedIndex != -1 then
print comboBox.SelectedItem
)
)
try(destroyDialog dotNetComboBoxTest)catch()
createDialog dotNetComboBoxTest
Thanks Shane & Yannick,
i tried to create a string like this
str = dotnetObject "string" "myString"
But that doesn’t work. So i tried
str = dotnetObject "system.string" "myString"
Which works just fine. So thanks again.
Klaas