Click here to Skip to main content
14,330,512 members
Rate this:
Please Sign up or sign in to vote.
See more:

How can I add a hyperlink as listbox item?

ListBox1.Items.Add(item, "")
Updated 5-Oct-19 4:06am
Mitchell J. 15-Mar-14 21:39pm
Do you want the URL to be clickable?
TheGoffy 15-Mar-14 21:45pm
i need the item to work as link, so when i click the item then it throws me to the i dont need to display the link. i just want my item to work as link.
TcJoshJohnson 15-Mar-14 22:26pm
You'll want to subscribe to SelectedIndexChanged or SelectedValueChanged and grab the SelectedItem property of your ListBox. Then, you can do what you'd like with the selected item such as call Process.Start() with the link.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

A very simple example of how you can treat list box items as links without displaying the actual URL:

private ListBox _listBox1;

public void Initialize()
    MyObject myObject = new MyObject();
    myObject.DisplayName = "Google";
    myObject.URL = "";

    _listBox1.DisplayMember = "DisplayName";
    _listBox1.SelectedIndexChanged += _ListBox1_SelectedIndexChanged;

private void _listBox1_SelectedIndexChanged(object pSender, EventArgs pArgs)
    MyObject myObject = (MyObject)_listBox1.SelectedItem;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100