using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace listbox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=.;integrated security=true;database=test");
con.Open();
SqlCommand cmd = new SqlCommand("select sname from student", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds, "student");
DataView dv = new DataView(ds.Tables[0]);
listBox1.DisplayMember = "sname";
listBox1.ValueMember = "sname";
listBox1.SelectionMode = SelectionMode.MultiExtended;
listBox1.DataSource = dv;
}
private void button1_Click(object sender, EventArgs e)
![C#中ListBox控件中当可以进行多选择时如何获取选中项的Value值 listbox获取选中的值](http://img.aihuau.com/images/31101031/31022844t01f659a410d9b9d824.png)
{
label1.Text = "";
for (int i = 0; i < listBox1.SelectedItems.Count; i++)
{
//MessageBox.Show(listBox1.GetItemText(listBox1.SelectedItems[i]));
label1.Text += listBox1.GetItemText(listBox1.SelectedItems[i]);
}
}
}
}