0

I want to make a list with links to certain folders appear based on choices made in two comboboxes. First idea that popped to mind was adding linklabels into a listbox but I cannot fathom how to actually make it work.

What I have so far:

private void button1_Click(object sender, EventArgs e)
{

        if (comboBox1.SelectedIndex == 0 && comboBox2.SelectedIndex == 0)
        { 
        LinkLabel label1 = new LinkLabel();


        label1.LinkArea = new LinkArea(0, 22);
        label1.Links.Add(24, 9, "E:\Folder");
        label1.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkedLabelClicked);
            listBox1.Items.Add(label1);
        }
}

where

private void LinkedLabelClicked(object sender, LinkLabelLinkClickedEventArgs e)
{              
     System.Diagnostics.Process.Start("E:\Folder");
}
Adriano Repetti
  • 65,416
  • 20
  • 137
  • 208
Alex M
  • 73
  • 6
  • WinForms isn't WPF, LinkLabel will only used to call its ToString() method (or to read one of its properties according to DisplayMember) to decide text to display but rendering is in charge to ListBox not to LinkLabel itself. Fortunately you can draw ListBox items by yourself to _simulate_ links appearance (and click is just...a click on ListBox itself). – Adriano Repetti Aug 01 '14 at 07:42
  • why don't you just handle the `Click` event of the ListBox? When you click on item in the ListBox you can check the selected index of the comboBox and then open the folder that you want. – Apostrofix Aug 01 '14 at 07:42
  • Check this question: http://stackoverflow.com/questions/456063/adding-button-into-a-listview-in-winforms it allows adding `Button` to list view. Maybe it will help to add a `LinkLabel` too. – sasha_gud Aug 01 '14 at 08:10

0 Answers0