日期:2014-05-19  浏览次数:20944 次

listBox控件问题
在listBox1有三个Item分别为book1,book2,book3
当我点选book1时在另一边textBox中显示book1中的内容,点book2时,显示book2的内容.


------解决方案--------------------
以上使用接口有什么好处?
比如有一个CD类也实现了IShow接口,那么可以用同一个textbox去显示它

class CD:IShow
{
public string Name;
public int Volume;
public decimal Price;
public CD(string name, int volume, decimal price) {
Name = name;
Volume = volume;
Price = price;
}

#region IShow 成员

public string ShowText
{
get { return string.Format( "片名:{0},{1}片装,价格:{2} ", Name, Volume, Price); }
}

#endregion

public override string ToString()
{
return Name;
}
}
------解决方案--------------------
晕! 处理ListBox的SelectedIndexChanged事件就可以啦...

ListBox listBox1 = new ListBox();

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.textBox.Text = this.listBox1.Items[this.listBox1.SelectedIndex].ToString();
}