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 6842455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:06:09+00:00 2026-05-27T00:06:09+00:00

I would like to thank contributors in advanced, I am rather stuck on this

  • 0

I would like to thank contributors in advanced, I am rather stuck on this one:

I have created a List View called listView1 and when the program runs it displays data files (.txt, .doc etc) from a particular folder specified in a Tree View called treeView1. In these same folders next to the data files are icon files(.ico). I would like to assign a .ico to be displayed as the image for the .txt or .doc file that will be loaded into listView1. Both the data file and icon file have the same name just a different extension. Therefor I already have a way of matching the icon file to the data file. However, I cannot seem to find a way to programically assign the icon file as the image to be displayed for the data file in listView1. I cannot use a Image List because you can only assign images from a image list based on its image index not its name. All signs seem to point to creating a array but I cannot figure out how to assign an image in a array to a data file while I am adding it to listView1.

I hope that makes sense, thank you!

  • 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-05-27T00:06:09+00:00Added an answer on May 27, 2026 at 12:06 am

    Once you have added your image files to an ImageList, you most certainly CAN refer to them by their name (the ImageKey property). The following code works. It is rather crude, because I have no idea how you are populating your Treeview or Listview with data. I just threw in some test data and used common means of populating Treenodes and ListViewItems.

    Hope this helps. Let me know if you have questions . . .

    public partial class Form1 : Form
    {
        // A Class member variable to hold images, to be used by both the 
        // TreeView AND the ListView:
        ImageList _myImagelist;
    
        public Form1()
        {
            InitializeComponent();
    
            // Initialize your memeber variable:
            _myImagelist = new ImageList();
    
            // Add some hokey test images for this arbitrary example:
            _myImagelist.Images.Add("Image1", Properties.Resources.SomeImage);
            _myImagelist.Images.Add("Image2", Properties.Resources.AnotherImage);
    
            // Some crude code to populate the list with test data:
            TreeView lst = this.treeView1;
            lst.ShowPlusMinus = true;
    
            // Set a reference to your member variable:
            lst.ImageList = _myImagelist;
    
            // Now populate your tree nodes and subnodes:
            TreeNode parent;
    
            //A parent . . .
            parent = lst.Nodes.Add("FirstNode", "Image One", "Image1");
    
            //  . . . with children:
            parent.Nodes.Add("P1:S1", "Parent One Child One", "Image1");
            parent.Nodes.Add("P1:S2", "Parent One Child Two", "Image1");
    
            // Another parent . . .
            parent = lst.Nodes.Add("SecondNode", "Image Two", "Image2");
    
            // . . . More children:
            parent.Nodes.Add("P2:S1", "Parent Two Child One", "Image2");
            parent.Nodes.Add("P2:S2", "Parent Two Child Two", "Image2");
        }
    
    
        // Event handler for the AfterSelect Event:
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode nd = e.Node;
            this.FillList(nd);
        }
    
    
        private void FillList(TreeNode node)
        {
            ListView lv = this.listView1;
            lv.View = View.List;
    
            // Set the reference to your same member variable:
            lv.SmallImageList = _myImagelist;
            lv.Items.Clear();
    
            foreach (TreeNode nd in node.Nodes)
            {
                // The Listview also has an override of the .Add method which accepts the image KEY as
                // an argument. The nd.ImageKey property returns a string, which the ListView item recognizes
                // as the key for an item in the referenced ImageList:
                ListViewItem newItem = new ListViewItem(nd.Text, nd.ImageKey);
                lv.Items.Add(nd.Name, nd.Text, nd.ImageKey);
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all I would like to thank all of the contributors of this
I would like to have more than one button. I tried to copy code
I would like to thank all the users in this community for helping me
Thank you for reading, I have two classes with two propertys. I would like
I would like to thank anyone with input on this ahead of time. I
First I would like to thank everyone for everything they have ever done for
Before everything i would like to thank you for your help I have a
As this is my first post here, I would like to thank all of
Right first of I would like to thank everyone for helping me out on
Once again my silliness has struck. I would like to thank everyone who helped

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.