SelectionChanged event handler not triggering

I'm having trouble with the following code, it isn't triggering the SflvDishList_SelectionChanged event handler when I press/select any of the objects in my Grid.

Below is my code:

public class vwGridView : Grid
    {
        public SfListView sflvDishList = new SfListView();
        public vmFoodDish _vmFoodDish;

        public  vwGridView()
        {
            Grid TestGrid = new Grid();
            RowDefinition MyRowMain = new RowDefinition();
            MyRowMain.Height = new GridLength(100, GridUnitType.Star);
            TestGrid.MinimumHeightRequest = 125d;
            _vmFoodDish = new vmFoodDish();
            
            sflvDishList.SelectionMode = SelectionMode.Single;
            sflvDishList.MinimumHeightRequest = 125d;
            sflvDishList.ItemSize = 125d;
            sflvDishList.ItemSpacing = new Thickness(5, 0, 0, 0);
            sflvDishList.Orientation = Orientation.Horizontal;
            sflvDishList.IsScrollBarVisible = false;

            // Create a Grid View
            sflvDishList.ItemTemplate = new DataTemplate(() =>
            {
                Grid myGrid = new Grid();

                Label myLabel = new Label();
                myLabel.SetBinding(Label.TextProperty, new Binding("Name"));
                myGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(100, GridUnitType.Star) });
                myGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(100, GridUnitType.Star) });

                myGrid.Children.Add(myLabel);

                return myGrid;
            });

            // Load Data
            sflvDishList.ItemsSource = _vmFoodDish.FoodDishes;
            sflvDishList.BindingContext = _vmFoodDish;

            // Event handler
            sflvDishList.SelectionChanged += SflvDishList_SelectionChanged;          

            TestGrid.Children.Add(sflvDishList);
            this.Children.Add(TestGrid);
        }

        private void SflvDishList_SelectionChanged(object sender, ItemSelectionChangedEventArgs e)
        {
            //throw new NotImplementedException();
        }
    }

Below is what the list view looks like on android emulator:


3 Replies

MK Muthu Kumaran Gnanavinayagam Syncfusion Team November 29, 2017 08:27 AM UTC

Hi Dennis, 
 
We have checked the reported query “SelectionChanged event does not trigger when selecting SfListView items” and referred the attached code snippet from our side. We would like to enlighten you that when the Syncfusion.SfListView.XForms.Android.dll is not added as reference in your android project, the SfListView renderers will not be initialized properly and leads to the reported issue. So you can please check whether the SfListView assemblies are properly added in your application? 
 
You can refer the below documentation link to know about the list of assemblies required to run SfListView effectively in your application. 
 
 
For your assistance, we have attached the working sample link below. 
 
 
Please let us know if you require further assistance. 
 
Regards, 
G.Muthu Kumaran. 



DF Dennis Fiedler November 29, 2017 10:06 AM UTC

I was missing the following references in my Droid solution:

cl\Syncfusion.DataSource.Portable.dll
pcl\Syncfusion.Core.XForms.dll
pcl\Syncfusion.GridCommon.Portable.dll
pcl\Syncfusion.SfListView.XForms.dll
android\Syncfusion.SfListView.XForms.Android.dll

I added those in and cleaned my solution and rebuilt it, and the event handler now works. Thanks Mutu!


DB Dinesh Babu Yadav Syncfusion Team November 30, 2017 06:44 AM UTC

Hi Dennis, 
 
Thanks for the update. 
 
Regards, 
Dinesh Babu Yadav 


Loader.
Up arrow icon