How to: Check a SwitchColumn by a Single Tap

This example illustrates how to implement the SwitchColumn value changing using a single tap (not a usual approach with opening an edit row). To add this functionality, follow the steps below.

  1. Set the GridControl.AllowEditRows property to false to disable the grid's editing row feature.
  2. Create an object (Data in this example) that implements the INotifyPropertyChanged interface and has a Boolean property (IsSelected in this example) that notifies a GridControl whether or not a corresponding cell is selected.
  3. Assign the DevExpress.Mobile.Core.Containers.BindingList<T> (T is the Data type in this example) collection to the GridControl.ItemsSource property.
  4. Subscribe to the GridControl.RowTap event and use its handler to change the Boolean property's (from step 2) value.
using System.ComponentModel;
using DevExpress.Mobile.Core.Containers;
using Xamarin.Forms;

namespace DXSample
{
    public partial class DXSamplePage : ContentPage
    {
        BindingList<Data> List = new BindingList<Data>();
        public DXSamplePage()
        {
            InitializeComponent();

            for (int i = 0; i < 10; i++)
            {
                Data data = new Data();
                data.Text = "Row " + i;
                data.IsSelected = (i % 2) == 0;

                List.Add(data);
            }

            grid.ItemsSource = List;
            grid.RowTap += (sender, e) => {
                if (e.FieldName == "IsSelected") {
                    int sourceRowIndex = grid.GetSourceRowIndex(e.RowHandle);
                    List[sourceRowIndex].IsSelected = !List[sourceRowIndex].IsSelected;
                }
            };
        }
    }

    public class Data : INotifyPropertyChanged {
        bool isSelected = false;
        public bool IsSelected { 
            get { return isSelected; }
            set {
                isSelected = value;

                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("IsSelected"));
            }
        }

        public string Text { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}