DevT
DevT

Reputation: 1511

Windows 8 GridView multi selected items

I am developing an application for Windows 8, I would like to select multiple items in a GridView (by c# code), I tried this:

1st

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

//in this way is only selects the third element

2nd

this.ItemGridView.SelectedItem = listPeople;

//in this way does not select anything 

3rd

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

//in this way is selected only the last

Upvotes: 1

Views: 922

Answers (2)

Epic Chen
Epic Chen

Reputation: 1382

You could try this

Assume the 'listPeople' is collection what you want to select.

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

Upvotes: 2

Filburt
Filburt

Reputation: 18061

I didn't try for Win8 but something like this should work:

this.ItemGridView.MultiSelect = true;

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

Upvotes: 0

Related Questions