PDA

View Full Version : PLEASE help me to understand this problem with Combobox vs Listbox!!



SteevieNiteHeat
03-07-2010, 05:26 AM
Right, I am appealing for help with helping me understand why the code I use for combobox will not work with listbox...

Example of what I mean is:

-- Adds 7 items to the combo box as shown below:-
ComboBox.AddItem("ComboBox1", "Day 1", "Monday");
ComboBox.AddItem("ComboBox1", "Day 2", "Tuesday");
ComboBox.AddItem("ComboBox1", "Day 3", "Wednesday");
ComboBox.AddItem("ComboBox1", "Day 4", "Thursday");
ComboBox.AddItem("ComboBox1", "Day 5", "Friday");
ComboBox.AddItem("ComboBox1", "Day 6", "Saturday");
ComboBox.AddItem("ComboBox1", "Day 7", "Sunday");
Button 1:
cb_Selected = ComboBox.GetSelected("ComboBox1");
cb_ItemText = ComboBox.GetItemText("ComboBox1", cb_Selected);
cb_ItemData = ComboBox.GetItemData("ComboBox1", cb_Selected);

Dialog.Message(cb_ItemText, cb_ItemData, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

BUT....


-- Adds 7 items to the list box as shown below:-
ListBox.AddItem("ListBox1", "Day 1", "Monday");
ListBox.AddItem("ListBox1", "Day 2", "Tuesday");
ListBox.AddItem("ListBox1", "Day 3", "Wednesday");
ListBox.AddItem("ListBox1", "Day 4", "Thursday");
ListBox.AddItem("ListBox1", "Day 5", "Friday");
ListBox.AddItem("ListBox1", "Day 6", "Saturday");
ListBox.AddItem("ListBox1", "Day 7", "Sunday");
Button 2:
lb_Selected = ListBox.GetSelected("ListBox1");
lb_ItemText = ListBox.GetItemText("ListBox1", lb_Selected);
lb_ItemData = ListBox.GetItemData("ListBox1", lb_Selected);

Dialog.Message(lb_ItemText, lb_ItemData, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1); DOES NOT work...

Also, attached is the sample project I am talking about.

So WHY wont the listbox work just like the combobox does with the same code? PLEASE help me to understand this!!

Imagine Programming
03-07-2010, 05:38 AM
Maybe you should read the manual on ListBox instead of simply renaming
the actions... ListBox.GetSelected returns a table instead of a number...

Try:


lb_Selected = ListBox.GetSelected("ListBox1");
if(lb_Selected)and(lb_Selected[1])then
lb_ItemText = ListBox.GetItemText("ListBox1", lb_Selected[1]);
lb_ItemData = ListBox.GetItemData("ListBox1", lb_Selected[1]);
Dialog.Message(lb_ItemText, lb_ItemData, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end



And before you ask, ListBox.GetSelected returns a table, because with multiselection enabled, multiple items can be selected. All these selected item's indexes will be inserted in that table.

SteevieNiteHeat
03-07-2010, 05:45 AM
Maybe you should read the manual on ListBox instead of simply renaming
the actions... ListBox.GetSelected returns a table instead of a number...

Try:


lb_Selected = ListBox.GetSelected("ListBox1");
if(lb_Selected)and(lb_Selected[1])then
lb_ItemText = ListBox.GetItemText("ListBox1", lb_Selected[1]);
lb_ItemData = ListBox.GetItemData("ListBox1", lb_Selected[1]);
Dialog.Message(lb_ItemText, lb_ItemData, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end


Thanks for the explanation!
I did read the help part, but what I have found is that help help and examples are only a tiny bit of help, as with what I found about ListBox.GetSelected is:

Example 1
List_Select = ListBox.GetSelected("File List");

Gets the indexes of all of the currently selected items in the "File List" listbox object and stores the results in a table called "List_Select."

Example 2
-- Get the indexes of the items currently selected in the listbox.
selected_items = ListBox.GetSelected("ListBox1");

-- If there were items selected in the listbox, display a dialog with their indexes.
-- If no items were selected, display a notification message.
if (selected_items ~= nil) then
output = "";
for index, item in selected_items do
output = output..item.."\r\n";
end
Dialog.Message("Selected Items", "The indexes of the selected items are:\r\n\r\n"..output);
else
Dialog.Message("Selected Items", "There are no selected items in the listbox.");
end

Gets the indexes of all of the currently selected items in the "ListBox1" listbox object and stores the results in a table called "selected_items." If any items were selected, their indexes are displayed in a dialog message. If no items were selected, a dialog message is shown notifying the user.

Which doesn't even come close to the example that you posted for me, please don't get me wrong, I am not having a go or being disrespectful, I AM gratefull for your explanation, which is what I wanted to know, I just wish the examples would show ALL the possible options and usages.

Imagine Programming
03-07-2010, 06:28 AM
Thanks for the explanation!
I did read the help part, but what I have found is that help help and examples are only a tiny bit of help, as with what I found about ListBox.GetSelected is:


Which doesn't even come close to the example that you posted for me, please don't get me wrong, I am not having a go or being disrespectful, I AM gratefull for your explanation, which is what I wanted to know, I just wish the examples would show ALL the possible options and usages.

If you read the complete AMS documentation, you'll find everything you need to know to do what I just did :) If you find out an action returns a table, start reading the helpfile about tables, and you'll see what you can do :) :yes

SteevieNiteHeat
03-07-2010, 06:30 AM
If you read the complete AMS documentation, you'll find everything you need to know to do what I just did :) If you find out an action returns a table, start reading the helpfile about tables, and you'll see what you can do :) :yes

cheers, I will look out for that in future :yes
Might even help me complete all the projects i got stuck on and just left :)

Imagine Programming
03-07-2010, 06:41 AM
cheers, I will look out for that in future :yes
Might even help me complete all the projects i got stuck on and just left :)

You should never quit because of limitations, always seek for answers,
plow through the helpfile, documentation, forums, searchfunction of the forum is awesome! google stuff, MSDN stuff, use winapi calls and learn! :yes