locked
Why is there no SelectedIndexChanged event for the GridView?

    Question

  • Hi,

    Am I missing it? Is there a way to trigger a method whenever the currently selected GridViewItem index changes?

    thnx

    Brian

    Wednesday, December 03, 2014 4:56 PM

Answers

  • Hi duffybr,

    Maybe you are missing the SelectionMode on the GridView. The following code works for me:

    <GridView
        x:Name="MyGridView"
        SelectionMode="Single"
        IsSwipeEnabled="True"
        IsItemClickEnabled="True"
        SelectionChanged="GridView_SelectionChanged"
        ... other properties such as ItemsSource
        /> 

    private void GridView_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (MyGridView.SelectedItems.Count() > 0)
        {
            // do something
        }
    }
    Leszek

    My Apps

    • Edited by ata6502 Wednesday, December 03, 2014 7:29 PM
    • Marked as answer by duffybr Wednesday, December 03, 2014 9:08 PM
    Wednesday, December 03, 2014 7:26 PM

All replies

  • Hi duffybr,

    Maybe you are missing the SelectionMode on the GridView. The following code works for me:

    <GridView
        x:Name="MyGridView"
        SelectionMode="Single"
        IsSwipeEnabled="True"
        IsItemClickEnabled="True"
        SelectionChanged="GridView_SelectionChanged"
        ... other properties such as ItemsSource
        /> 

    private void GridView_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (MyGridView.SelectedItems.Count() > 0)
        {
            // do something
        }
    }
    Leszek

    My Apps

    • Edited by ata6502 Wednesday, December 03, 2014 7:29 PM
    • Marked as answer by duffybr Wednesday, December 03, 2014 9:08 PM
    Wednesday, December 03, 2014 7:26 PM
  • Great, thanks for that.
    Wednesday, December 03, 2014 9:08 PM