在 C# 中将自定义类对象添加到列表框
我有一个看起来像这样的类,
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 中实现这一目标?
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; }
}
}
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该使用 ListView 控件并添加两列(ListBox 只有一列)
You should use a ListView control and add two columns (ListBox only has one column)
列表框具有向用户显示的单个ListItem(字符串)。
因此,您可以重写 ToString() ,因为
如果这是用于 winforms 应用程序,请查看 ListView 控件或 DataGridView
A list box has a single ListItem (string) displayed to the user.
So you could override ToString() as
If this is for a winforms app, have a look at the ListView Control or a DataGridView
您对列表使用哪种类型的控件? 如果您使用 ListView,那么您可以这样做(假设 instance 是一个 Process_Items - 顺便说一句,对于 IMO 类实例来说,这是一个奇怪的名称):
What kind of control do you use for the list? If you use a ListView, then you can do like this (assuming that instance is a Process_Items - which btw is a strange name for a class IMO - instance):