0

Hi guys,how are you? =)
i have a doubt,with ListBox =/
i want to get the selected item the user clicks and then put in another listbox,but it´s not happening,it says 'cannot be indexed because it has no default property'
is there an easy way to solve it?
my code is below:

Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        If (ListBox1.SelectedItem(1)) Then
            ListBox2.Items(0).Value = "Click 1X"
            ListBox2.Items(1).Value = "Click 2X"
            ListBox2.Items(2).Value = "Click 3X"
            ListBox2.Items(3).Value = "Search + Click 1X"
            ListBox2.Items(4).Value = "Search + Click 2X"
        End If
        
end Sub

thanks!

Edited by __avd: Added [code] tags.

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by vuyiswamb
0

ok, i am a C# man, but you can easly Convert the code.

first , in the first listbox you dont need to check every item. in the ListBox1_SelectedIndexChanged you must have only one line, this line will add the item in the second listbox like this

ListBox2.Item.add(ListBox1.selectedItem);

this is just an example code, i did not copy form Vs, this is to show you how you could do it.

Regards

Vuyiswa Maseko

0

Hi,thanks for answering!
But making a listBox.Item.Add would add the item from listbox1 to the listbox2 right?
The thing is when it clicks an item from listbox 1,it opens different values from listbox 2,like for example, u have category 'food' in listbox1 with vegetable and meat,so when u click 'meat' in listbox1 will appear 'beef' and 'steak' in listbox2 and when u click in vegetable will appear ' raddish' and 'cucumber' =)
also,would be possible to do this without refreshing the page?and without using ajax?i guess the users get annoyed with so many refreshments =)

0

But making a listBox.Item.Add would add the item from listbox1 to the listbox2 right?
Yes

here is my Example

<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" 
        onselectedindexchanged="ListBox1_SelectedIndexChanged">
        <asp:ListItem>Food</asp:ListItem>
        <asp:ListItem>Vegetable</asp:ListItem>
        <asp:ListItem>Meat</asp:ListItem>
    </asp:ListBox>
    <asp:ListBox ID="ListBox2" runat="server" AutoPostBack="True"></asp:ListBox>

and on the Server side

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           

        }

        protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListBox2.Items.Add(ListBox1.SelectedValue);
        }
    }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.