日期:2014-05-18  浏览次数:20751 次

listview多选.只能得到最后一条!
绑定id到tag上.
C# code

string[] listArr = new string[] { user, name, pass, smsUState, smsContent, tmpAllToMob.ToString(), sender_name };
ListViewItem listLV = new ListViewItem(listArr);
listLV.Tag = Convert.ToInt32(dr["Id"]);
toplist.Items.Add(listLV);



C# code

private void button1_Click(object sender, EventArgs e)
{
string myid = toplist.SelectedItems[0].Tag.ToString();
MessageBox.Show(myid);
}



多选了.但是得到的ID只有一个.怎么样才能得到所有选择的tag

------解决方案--------------------
for(int i = 0; i < toplist.SelectedItems.Count; i++)
{
string myid = toplist.SelectedItems[i].Tag.ToString();
}
------解决方案--------------------
forech(ListViewItem listLV in toplist.SelectedItems) 
{
}


------解决方案--------------------
string myid ="";

for(int i = 0; i < toplist.SelectedItems.Count; i++) 

myid += toplist.SelectedItems[i].Tag.ToString(); 
}
------解决方案--------------------
探讨
listview的checkboxes设置为true,选择框为什么不起作用?

------解决方案--------------------
C# code

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 3; i++)
            {
                string[] listArr = new string[] { "user", "name" };
                ListViewItem listLV = new ListViewItem(listArr);
                listLV.Tag = i;
                this.listView1.Items.Add(listLV);
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.listView1.SelectedItems.Count; i++)
            {
                string myid = this.listView1.SelectedItems[i].Tag.ToString();
            }
        }