惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The GitHub Blog
The GitHub Blog
J
Java Code Geeks
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Vercel News
Vercel News
腾讯CDC
博客园 - 聂微东
The Cloudflare Blog
F
Fortinet All Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
Last Week in AI
Last Week in AI
B
Blog

博客园 - lining

输出的客户端 - lining - 博客园 List<T> - lining - 博客园 DateTime 赋空值 配色达人速成 批处理文件,删除文件及文件夹 - lining - 博客园 Source Code中pfx的密码 查找所有有某一列的表 如何修改 app.config 的配置信息 用例的获得 如何oracle调试存储过程 C# 中String 和 string 有什么区别 ora-00997:非法使用LONG数据类型 oracle如何判断一个字符串是否为数字或日期 C# 中的计时器 populate a listbox on winform with values from database 查看oracle执行计划 “Windows Workflow Foundation开发实战系列课程”中的数据库恢复 ASP.NET多语言版的开发 oracle数据导入导出imp/exp命令
winform技巧,listbox绑定,value,text, - lining - 博客园
lining · 2010-06-18 · via 博客园 - lining

from->http://www.cnblogs.com/virusswb/articles/1206888.html

private void button1_Click(object sender, EventArgs e)
{
    List<Vector> list = new List<Vector>();
    list.Add(new Vector("swb1", 1));
    list.Add(new Vector("swb2", 2));
    list.Add(new Vector("swb3", 3));
    list.Add(new Vector("swb4", 4));
    list.Add(new Vector("swb5", 5));
    listBox1.DataSource = list;
    listBox1.DisplayMember = "Name";
    listBox1.ValueMember = "Id";
    this.textBox1.Text = "Id";
    this.textBox2.Text = "Name";
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    //this.textBox1.Text = listBox1.SelectedItem
    object obj = listBox1.Items[this.listBox1.SelectedIndex];
    this.textBox1.Text = ((Vector)obj).Name;
    this.textBox2.Text = listBox1.SelectedValue.ToString(); ;
}

class Vector
{
    private string _name;
    private int _id;

    public string Name
    {
        get { return this._name; }
        set { this._name = value; }
    }
    public int Id
    {

        get { return this._id; }
        set { this._id = value; }
    }
    public Vector()
    { }
    public Vector(string name, int id)
    {
        this._name = name;
        this._id = id;
    }
}