日期:2014-05-20  浏览次数:20881 次

求助:关于ListBox的一个问题?
如下代码:
for(int   i   =   0;i <this.listBox2.SelectedItems.Count;i++)
{
        this.listBox1.Items.Add(this.listBox2.SelectedItems[i].ToString());
}
为何this.listBox2.SelectedItems[i].ToString()总是输出为 "System.Data.DataRowView ",而不是所选的显示项?我的listBox2的显示项是从数据库中得到的。万分感谢!

------解决方案--------------------
oracle example:

private void Form1_Load(object sender, EventArgs e)
{
DataBind();
}
private void DataBind()
{
OleDbConnection con = new OleDbConnection( "Provider=OraOLEDB.Oracle.1;data source=oracle;user id=***;password=*** ");
OleDbDataAdapter sda = new OleDbDataAdapter( "select * from student ", con);
DataSet ds = new DataSet();
sda.Fill(ds, "student ");
this.listBox1.DataSource = ds.Tables[ "student "];
this.listBox1.DisplayMember = "sname ";
}

private void button1_Click(object sender, EventArgs e)
{
foreach (DataRowView dv in this.listBox1.SelectedItems)
{
listBox2.Items.Add(dv .Row[ "sname "].ToString ());
}
}