在C#中将自定义类对象添加到列表框 [英] Adding custom class objects to listbox in c#
本文介绍了在C#中将自定义类对象添加到列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来像这样的类
i have a class which looks like this
public class Process_Items
{
String Process_Name;
int Process_ID;
//String Process_Title;
public string ProcessName
{
get { return Process_Name; }
set { this.Process_Name = value; }
}
public int ProcessID
{
get { return Process_ID; }
set { this.Process_ID = value; }
}
}
现在我想创建一个Process_Items []数组并在多列列表框中显示所有元素。这样第一列必须具有processName,第二列必须具有processID。我该如何在C#2.0中实现这一目标?
now i want to create a Process_Items[] Array and display all the elements in a multi column listbox. Such that first column must have the processName and 2nd must have the processID. How can i achieve this in C# 2.0?
推荐答案
您应该使用ListView控件并添加两列(ListBox只有一列)
You should use a ListView control and add two columns (ListBox only has one column)
Process_Items[] items = new Process_Items[] // Initialize array
foreach(Process_Items p in items) {
listView.Items.Add(p.ProcessName).Subitems.Add(p.ProcessID.ToString());
}
这篇关于在C#中将自定义类对象添加到列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文