如何使用一个按钮获取12个值的数组列表中列表框项的所有值?
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";
答案 0 :(得分:2)
如果你希望在列表框中插入到ArrayList中,那么你必须使用一个循环
ArrayList myAL = new ArrayList();
for(int i = 0; i < dt.Rows.Count; i++)
myAl.Add(dt.Rows[i]["Name"].ToString());
如果您还想在此添加ID Dictionary
,可以在这里找到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());