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


Recommended Answers

All 3 Replies

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


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


Vuyiswa Maseko

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 =)

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

here is my Example

<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" 
    <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)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.