| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 885 人关注过本帖, 1 人收藏
标题:关于ListBox中保存对象的解决,请高手指点
只看楼主 加入收藏
ngnming
Rank: 1
来 自:沈阳
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-7-18
收藏(1)
 问题点数:0 回复次数:0 
关于ListBox中保存对象的解决,请高手指点
namespace ListBoxTest
{
public partial class Form1 : Form
{
ArrayList al = new ArrayList();
public ArrayList GetArrayListItemAll()
{
al.Add(new ListBoxItemsAll("周润发", 40));
al.Add(new ListBoxItemsAll("张学友", 45));
al.Add(new ListBoxItemsAll("周杰伦", 30));
al.Add(new ListBoxItemsAll("巩俐", 40));
al.Add(new ListBoxItemsAll("张韶涵", 28));
return al;
}
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
ArrayList listboxitems = GetArrayListItemAll();
this.listBox1.DataSource = listboxitems;
foreach (ListBoxItemsAll a in listboxitems)
{
this.listBox1.Items.Add(a.Name);
//此处如何记住对象项的ListBoxItemsAll对象?
}

}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}
}
public class ListBoxItemsAll
{
public ListBoxItemsAll(string name, int age)
{
this.name = name;
this.age = age;
}
private string name;
private int age;
public string Name
{
get { return name; }
set { name = value; }
}
public int Age
{
get { return age; }
set { age = value; }
}
}
这个程序是我刚看了视频写的,ListBox1里面添加的是类ListBoxItemsAll的name,但是我现在要点击ListBox1然后将对应ListBoxItemsAll的对象提取出来,怎么做?请高人指点,我是新手

ArrayList里面是一些ListBoxItemsAll的对象,但是ListBox1里只有改对象的一个属性值,如何将ListBox1的选项和对应的ListBoxItemsAll的对象绑定在一起呢?
搜索更多相关主题的帖子: ListBox 对象 保存 
2008-07-18 09:23
快速回复:关于ListBox中保存对象的解决,请高手指点
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011218 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved