Windows 8 GridView多选项目

时间:2012-05-15 08:31:08

标签: silverlight xaml gridview windows-8

我正在为Windows 8开发一个应用程序,我想在GridView中选择多个项目(通过c#代码),我试过这个:

第1次

for (int i = 0; i <= 2; i++)
{ 
    this.ItemGridView.SelectedIndex = i;
}

//in this way is only selects the third element

第二

this.ItemGridView.SelectedItem = listPeople;

//in this way does not select anything 

第三

foreach (Persona persona in listaPersone)
{
    this.ItemGridView.SelectedItem = person;
}

//in this way is selected only the last

2 个答案:

答案 0 :(得分:2)

你可以试试这个

假设'listPeople'是你想要选择的集合。

foreach(var p in listPeople)
{
    this.ItemGridView.SelectedItem.Add(p);
}

答案 1 :(得分:0)

我没有尝试使用Win8,但这样的事情应该可行:

this.ItemGridView.MultiSelect = true;

foreach (GridViewRow row in this.ItemGridView.Rows)
{
    row.Selected = selection.Contains(row.Cells[0].Value);
}
相关问题