我用ListBox绑定了从数据库的查询结果,分别设置了DisplayMember和ValueMember,如果通过一个循环取得ListBox中所有项的Text和Value。

解决方案 »

  1.   

    我也不知道行不,试试:
    int count=this.listBox1.Items.Count;
    for(int i=0;i<count;i++)
    {
      string a= this .listTotalQuesType .ValueMember [i].ToString();
      string b= this .listTotalQuesType .Items[i].ToString();
    }
      

  2.   

    text:yourListBox.GetItemText( yourListBox.Item[i] );
      

  3.   

    Sample code as follows:
    for( int i = 0; i < yourListBox.Items.Count; i++ )
    {
         DataRowView drv = yourListBox.Items[i] as DataRowView;
         if( drv != null )
         {
               MessageBox.Show( "Text:" + drv[yourListBox.DisplayMember].ToString() );
               MessageBox.Show( "Value:" + drv[yourListBox.ValueMember].ToString() );
         }
    }