[英]Getting the values from all the items in listbox in an arraylist.Win forms
如何使用一個按鈕獲取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";
如果你希望在列表框'valuemembers'中插入ArrayList,你必須使用循環
ArrayList myAL = new ArrayList();
for(int i = 0; i < dt.Rows.Count; i++)
myAl.Add(dt.Rows[i]["Name"].ToString());
如果您還想添加ID,可以在此處使用Dictionary
,您可以找到mdsn參考鏈接
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());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.