Loading...

Google-Desktop-Developer@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: Dynamically append and delete items to and from a listbox Wagner Nitsch Thu Jan 28 22:00:15 2010

Hello mrf.

If you want to know the string of an item in the listbox, you can try this:

listbox1.children(0).children(0).innerText


The first child is the child of the listbox, because the listbox is an array
of items. The second child is the child of the item(0), a label.
You can try a similar method in the combobox:

combobox1.selectedItem.children(0).innerText


/********************************************************************************************/
Below you can see the entire code you need:

function button1_onclick() {
//function to copy an item from combobox1 to listbox1
    var iLoop1 = 0;
    var bFound = false;

    if (combobox1.selectedIndex == -1)
    {
        view.alert("Select an item to insert");
        return;
    }

    while (iLoop1 <= listbox1.children.count-1 && !bFound)
    {
        bFound = (listbox1.children(iLoop1).children(0).innerText ==
combobox1.selectedItem.children(0).innerText);
        iLoop1++;
    }

    if (bFound)
    {
        view.alert("This item already exist");
    }
    else
    {
        listbox1.appendString(combobox1.value);
    }
}

function button2_onclick() {
//function to remove an item from listbox1
    if (listbox1.selectedIndex==-1)
    {
        view.alert("Select an item to delete");
        return;
    }
    else
    {
        listbox1.removeElement(listbox1.selectedItem);
    }
}

/********************************************************************************************/

If your list is too long, it's recommended to use binary search:
http://en.wikipedia.org/wiki/Binary_search


Best Regards,
Wagner Nitsch Bressan.


On Tue, Jan 26, 2010 at 9:55 AM, mrf <[EMAIL PROTECTED]> wrote:

> Hey Mr. Wanger, First of all thank u very much for responding my
> question.
> However i appended in the similar way which u explained but, one more
> problem is that I am able to finding the size of a list using
> listbox1.children.count and now how could I get the (name or) value of
> a item in the list box before selection..?? Coz i found selectedIndex
> property in our API, which is working only when selecting
> (highlighting) the item.. So, How could i know the name of the items
> already existing in the list.... Please, do answer for this question
> tooo....
>
> Thank u in advance..
>
> On Jan 26, 7:10 am, Wagner Nitsch <[EMAIL PROTECTED]> wrote:
> > Hello mrf,
> >
> > To append an item from a combobox to a listbox, try this:
> >
> > listbox1.appendString(
> > combobox1.value);
> >
> > If you want to put the string in a specific position, try this:
> >
> > listbox1.insertStringAt(combobox1.value,1);
> > //The string will be insert at the second position
> >
> > //Don't forget to make a loop to check if the element wasn't previously
> > included
> >
> > To remove an element to the listbox, try this:
> >
> > listbox1.removeElement(listbox1.selectedItem);
> >
> > //Do not forget to check if an item was selected
> >
> > Best Regards,
> > --
> > Wagner Nitsch Bressan
> >
> >
> >
> > On Wed, Jan 20, 2010 at 6:03 AM, mrf <[EMAIL PROTECTED]> wrote:
> > > Hi friends., i need help in appending items to a list box
> > > dynamically.,
> > > In my gadget I have a items in combo box and now based on the selected
> > > item in the combobox i need to append those values in a list.
> > > In brief,I need to show the selected items back to the user which are
> > > chosen by him from a combobox.
> >
> > > However,I tried to display the selected items from combo box to a list
> > > and after that the most big issue am facing is, wat if the user want
> > > to delete the item in the listbox which he was appended earlier from
> > > combobox..??
> >
> > > Please, also kindly suggest me.,wat I hav tried here is
> > > listbox.selectedIndex to know the selected item in listbox but i'm
> > > failing to delete by using that index.
> >
> > > Your reply, helps me a lot... Please friends i know that u people help
> > > me but wat am requesting u is do the help as soon as possible...
> > > Thanks in advance
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Google Desktop Developer Group" group.
> > > To post to this group, send email to
> > > [EMAIL PROTECTED]
> > > To unsubscribe from this group, send email to
> > > [EMAIL PROTECTED]<[EMAIL PROTECTED]>
> <[EMAIL PROTECTED]<[EMAIL PROTECTED]>
> >
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/google-desktop-developer?hl=en.
> >
> > --
> --
> You received this message because you are subscribed to the Google Groups
> "Google Desktop Developer Group" group.
> To post to this group, send email to
> [EMAIL PROTECTED]
> To unsubscribe from this group, send email to
> [EMAIL PROTECTED]<[EMAIL PROTECTED]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-desktop-developer?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Desktop Developer Group" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-desktop-developer?hl=en.