2014-03-02 54 views
0

如何通过一个按钮获取12个值的数组列表中的列表框项目的所有值?从arraylist中的列表框中的所有项目中获取值.Win表单

SqlDataAdapter sda = new SqlDataAdapter("SELECT PLAYERS.ID, PLAYERS.SURNAME + ', ' + PLAYERS.FIRSTNAME AS PLAYER FROM PLAYERS INNER JOIN TEAMS ON PLAYERS.TEAM_ID = TEAMS.ID WHERE (TEAMS.NAME =oly", con); 
DataTable dt = new DataTable(); 
sda.Fill(dt); 

listBox1.DataSource = dt; 
listBox1.DisplayMember = "PLAYER"; 
listBox1.ValueMember = "ID"; 

回答

2

如果你想插入到ArrayList中ionly列表框” valuemembers的,你必须使用一个循环

ArrayList myAL = new ArrayList(); 
for(int i = 0; i < dt.Rows.Count; i++) 
    myAl.Add(dt.Rows[i]["Name"].ToString()); 

如果你还想加你可以在这里使用Dictionary的ID,你可以找到MDSN参考link

Dictionary<string,string> dictionary=new Disctionary<string,string>(); 
for(int i=0; i <dt.Rows.Count;i++) 
    dictionary.Add(dt.Rows[i]["ID"].ToString(),dt.Rows[i]["Name"].ToString()); 
+0

太棒了!!!绝对 – Apollon

相关问题