[Gambas-user] How can I copy an object
rolf
rolf.frogs at ...221...
Fri Sep 8 13:01:23 CEST 2006
Hello Timothy
> > I need a combobox with 5 or 6 entries more then once and have to setup an
> > array to manage them. Collect and access the comboboxes in the
> > array is no problem, but can I create a "sample combobox" with all the
> > wanted entries and copy this box, of course with a different name and a
> > different position into the array as offen as needed?
> Why swap over complete objects. The ComboBox (like the ListBox) has a List
> property that can easily be used to get or update the ComboBox content.
>
> In older versions of Gambas this was a string with each item separated by a
> new line. In the latest version of Gambas it is a string array. (There is
> no explanation for the change.)
>
> So a better answer is to use the list property. For example:
>
> Place 3 buttons on a form.
> Give the buttons the tags of 0, 1 and 2 and the group name of
> ButtonContent.
> Add a ComboBox and call it ComboBoxContent
>
> Try this code. The first bit just creates the string arrays for the items.
> Then swapping over the content is one line.
>
> PRIVATE comboContent AS Object[]
>
> PUBLIC SUB Form_Open()
> DIM i AS Integer
> DIM content AS String[]
> comboContent = NEW Object[3]
> ' Create 3 string arrays for the combo box content
> ' This is for button 1
> content = NEW String[10]
> FOR i = 0 TO content.Count - 1
> content[i] = "Button 1 content " & i
> NEXT
> comboContent[0] = content
> ' This is for button 2
> content = NEW String[24]
> FOR i = 0 TO content.Count - 1
> content[i] = "Button 2 item number " & i
> NEXT
> comboContent[1] = content
> ' This is for button 3
> content = NEW String[4]
> FOR i = 0 TO content.Count - 1
> content[i] = "No much in button 3 # " & i
> NEXT
> comboContent[2] = content
> ' Set the conbo box to button 1 items
> ComboBoxContent.List = comboContent[0]
> END
>
> PUBLIC SUB ButtonContent_Click()
> ComboBoxContent.List = comboContent[LAST.Tag]
> END
I will test the code - if I know, why I get in a listbox_click event allways
the previous (if exists) and the current item under GAMBAS 1.9.39
Fine regards
Rolf
More information about the User
mailing list