C#中的Listview控件 [英] Listview control in C#
本文介绍了C#中的Listview控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello All,
我必须在我的应用程序中显示以下字段的一个列表视图。
1)服务器名称:{让我们说CHI_DEV)
2)网络连接:{让我们说HTTP}
3)状态:{让我们说:绿球图像好,黄球图片需要注意,红色球图片为关键ALERT}
你能告诉我如何用这种方式格式化listview吗?
这里我必须每隔10分钟刷新一次这个列表视图,这样我的状态就会在这个例子中改变因素。
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.
推荐答案
所以来自你的图片链接我假设你正在使用WindowsForms项目。
看看这个可运行的例子。不要忘记用你系统的有效路径替换图像路径...
这应该让你知道如何使用System.Windows.Forms.ListView
。但如果你想要更灵活的东西,我会使用System.Windows.Forms.DataGridView
...
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 aSystem.Windows.Forms.ListView
. But if you want something more flexible I''d use aSystem.Windows.Forms.DataGridView
...
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);
}
}
}
这篇关于C#中的Listview控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文