Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello All ,

I have to show one list view in my application with below fields.
1) Server name : {Lets say "CHI_DEV")
2) Network Connectivity : {Lets say "HTTP"}
3) Status :{Lets say : Green ball image for OK , yellow ball image for Need attention , Red ball image for CRITICAL ALERT}

Could you please tell me how to format listview in this way ?

Here I have to refresh this list view at every 10 min so that my status will be changing factor in this example.
Posted
Comments
Sergey Alexandrovich Kryukov 17-Apr-13 2:14am    
No, no. When you say "ListView", you should, first of all, tell us its fully-qualified type name. Do you think there is only one ListView type? No.
—SA
RDBurmon 17-Apr-13 2:22am    
See this :
http://www.imagecross.com/d/image-hosting-view-02.php?id=4825Listview.png
Manfred Rudolf Bihy 17-Apr-13 2:42am    
SA asked about the fully qualified type name and you answer by posting a link to a picture.
Are you serious? If you don't know what a fully qualified type name is then look it up.

Please!
RDBurmon 17-Apr-13 2:45am    
I am sorry , I don't know about this term . I just need one detail grid where I can show this details as well as image in last column which will be refresh in every 10 mins

1 solution

So from your picture-link I assume you are using a WindowsForms project.

Have a look at this runnable example. Don't forget to replace the image paths with valid paths for your system...

This should give you an idea how to use a System.Windows.Forms.ListView. But if you want something more flexible I'd use a System.Windows.Forms.DataGridView ...

[EDIT: AAAHHH the crazy auto-correction making all the capitals!]

using System;
using System.Drawing;
using System.Windows.Forms;

namespace ListViewTest.Forms
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            // Create example form
            Form form = new Form();

            // Create ImageList for state images
            ImageList imagelist = new ImageList();
            // use valid image paths or other image resources!
            imagelist.Images.Add(new Bitmap(@"C:\Images\ImageOk.png"));
            imagelist.Images.Add(new Bitmap(@"C:\Images\ImageAlarm.png"));

            // Create example ListView:
            ListView listview = new ListView();
            listview.Dock = DockStyle.Fill;
            listview.View = View.Details;
            listview.FullRowSelect = true; ;
            listview.SmallImageList = imagelist; // WireUp the ImageList with the ListView
            // ... add some columns
            listview.Columns.AddRange(new ColumnHeader[] {
                new ColumnHeader { Text = "Server" },
                new ColumnHeader { Text = "Connectivity" },
                new ColumnHeader { Text = "Status"  }
            });
            
            // Add some example items to ListView 
            // (we use the ImageList's index to set the pictures)
            listview.Items.AddRange(new ListViewItem[] {
                new ListViewItem(new string[] { "CHI_ADM", "HTTP", "OK" }, 0),
                new ListViewItem(new string[] { "CHI_DEV", "HTTP", "CRITICAL" }, 1),
                new ListViewItem(new string[] { "CHI_USR", "HTTP", "OK" }, 0)
            });



            // Add ListView to example Form
            form.Controls.Add(listview);

            // Run example form
            Application.Run(form);
        }
    }
}
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900