Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8443981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:17:09+00:00 2026-06-10T09:17:09+00:00

I’ve been having a problem with the following code: namespace Viewer { public partial

  • 0

I’ve been having a problem with the following code:

namespace Viewer
{
    public partial class Form1 : Form
    {
        int count = 0;
        LinkLabel[] linkLabel = new LinkLabel[200];
        string filename;
        string extension;
        string filepath;

        private void btnLoad_Click(object sender, EventArgs e)
        {
            // Creates a Directory for the Movies Folder
            DirectoryInfo myDirectory = new DirectoryInfo(@"C:\Users\User\Movies");

            // Creates a list of "File info" objects
            List<FileInfo> ls = new List<FileInfo>();

            // Adds filetypes to the list
            ls.AddRange(myDirectory.GetFiles("*.mp4"));
            ls.AddRange(myDirectory.GetFiles("*.avi"));

            // Orders the list by Name
            List<FileInfo> orderedList = ls.OrderBy(x => x.Name).ToList();

            // Loop through file list to act on each item
            foreach (FileInfo filFile in orderedList)
            {
                // Creates a new link label
                linkLabel[count] = new LinkLabel();

                // Alters name info for display and file calling
                filepath = filFile.FullName;
                extension = filFile.Extension;
                filename = filFile.Name.Remove(filFile.Name.Length - extension.Length);

                // Write to the textbox for functional display
                textBox1.AppendText(filename + "\r\n");

                // Alters link label settings
                linkLabel[count].Text = filename;
                linkLabel[count].Links.Add(0, linkLabel[count].Text.ToString().Length, filepath);
                linkLabel[count].LinkClicked += new LinkLabelLinkClickedEventHandler(LinkedLabelClicked);

                // Adds link label to table display
                tblDisplay.Controls.Add(linkLabel[count]);

                // Indexes count up for arrays
                count = count + 1;
            }
        }

        private void LinkedLabelClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start(filepath);
        }

    }
}

My goal is to generate a table of links to all of the media files that I add at launch, and have the links open the files in their respective players.

As of right now, it generates all of the links properly, but whenever I click on any of them, it launches the last item in the list.

For example, if the list contains “300”, “Gladiator”, and “Top Gun”, no matter which link I click, it opens “Top Gun”.

I assume that this has to do with it calling the variable “filepath” in the click event, which is left in it’s final state. However, I’m not exactly clear on how to create a static link value or action on each individual link, as all of the answers I’ve researched are in regards to single linklabel situations, not dynamic set-ups.

Any help/advice would be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:17:10+00:00Added an answer on June 10, 2026 at 9:17 am

    Try as below:
    In foreach loop add one line more like:

    linkLabel[count].Tag = filepath;
    

    then in click event get this path as blow,

    private void LinkedLabelClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        string filepath = ((LinkLabel)sender).Tag.tostring();
        System.Diagnostics.Process.Start(filepath);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.