0

I have been reading up on dynamic link labels, and yet, I have not found my answer. In my code, I am reading off of a .csv file, with the basic setup that checks the lines and if every third one is filled, its a link. This all is in a tableLayoutPanel mind you. I'm creating the label like so:

        tableLayoutPanel1.Controls.Add(new LinkLabel() { Text = "TEST",Name = count.ToString(),Tag = @"N:\reuther", Anchor = AnchorStyles.Left, AutoSize = true }, 2, 3);

The problem that I'm having, is that some of these columns could be empty, meaning I really don't know how many in total I will have at any moment. Any notes I have seen online, name the dynamic link, and then proceed to use a private function detecting that the particular link by name was clicked. I can't do that because I will never know how many links will be needed until runtime. I can(and did) in my example, name the link, is there anyway to use a generic .Click event that will detect any click, at which point I can just have it open the path by tag? Is there any other way to go around this?

Thank you.

Marshal Alessi
  • 105
  • 2
  • 2
  • 11

1 Answers1

0

With a little more tinkering, I solved the issue.

LinkLabel[] linkLabel = new LinkLabel[100];

        linkLabel[count] = new LinkLabel();
        linkLabel[count].Tag = @"N:\reuther";
        linkLabel[count].Text = "Click Me";
        tableLayoutPanel1.Controls.Add(linkLabel[count], 3, 4);

    private void LinkedLabelClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        string filepath = ((LinkLabel)sender).Tag.ToString();
        System.Diagnostics.Process.Start(filepath);
    }

In this method, I created an array that stores 100 link labels. As I create them, I use a counting method to count how many links have been created. With each link, I used .Tag to set the filepath, and finally set the string filepath to the Tag, which allowed me to open it with the line afterwards. Thank you.

Marshal Alessi
  • 105
  • 2
  • 2
  • 11