首先,你可以用一个财产留给你的DisplayMember,让我们说:
ListBox1.DisplayMember = "team1";
现在,去你的形式一个[设计]米ode, 右键单击列表框 - >属性。
在属性窗口的顶部,点击活动(闪电图标),
看看在下面的事件列表格式(属性更改下),然后键入有一些事件名称,比方说:ListBox1Format,和按Enter键。你会看到这一点:
private void ListBox1Format(object sender, ListControlConvertEventArgs e)
{
}
现在写这些下面的行内:
private void ListBox1Format(object sender, ListControlConvertEventArgs e)
{
// Assuming your class called Scores
string team1 = ((Scores)e.ListItem).team1.ToString();
string team2 = ((Scores)e.ListItem).team2.ToString();
string battingteam = ((Scores)e.ListItem).battingteam.ToString();
string score = ((Scores)e.ListItem).score.ToString();
e.Value = team1 + " vs " + team2 + ": " + battingteam +" Score: " + score;
}
就是这样;)
你使用的是WinForms还是WPF? – Dennis 2010-06-23 00:45:11
我正在使用WinForms – SMUsamaShah 2010-06-23 01:09:46
,其格式为您的数据.. ?? – 2010-06-23 02:00:06