using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace FilesMove
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
listBox1.DisplayMember = "Text";
listBox1.ValueMember = "Value";
List<ListItem> list = new List<ListItem>();
list.Add(new ListItem("a", 1));
list.Add(new ListItem("b", 2));
list.Add(new ListItem("c", 3));
listBox1.DataSource = list;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(((ListItem)listBox1.SelectedItem).Text);
MessageBox.Show(((ListItem)listBox1.SelectedItem).Value.ToString());
}
}
public class ListItem
{
private string _Text;
public string Text
{
get { return _Text; }
set { _Text = value; }
}
private object _Value;
public object Value
{
get { return _Value; }
set { _Value = value; }
}
public ListItem(string text, object value)
{
_Text = text;
_Value = value;
}
}
}
|