SfDataGrid sfGrid;
ViewModel viewModel;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
sfGrid = new SfDataGrid(BaseContext);
viewModel = new ViewModel();
sfGrid.ItemsSource = viewModel.OrdersInfo;
sfGrid.SelectionMode = SelectionMode.Multiple;
Button selectedItems = new Button(this.BaseContext);
selectedItems.Text = "Set Selection";
selectedItems.Click += SetSelection_Click;
LinearLayout layout = (LinearLayout)FindViewById(Resource.Id.Linear);
layout.AddView(selectedItems);
layout.AddView(sfGrid);
}
void SetSelection_Click(object sender, EventArgs e)
{
//For adding an item in SelectedItems
sfGrid.SelectedItems.Add(viewModel.OrdersInfo[0]);
//For removing an item in SelectedItems
sfGrid.SelectedItems.RemoveAt(0);
//For clearing the Selection
sfGrid.SelectedItems.Clear();
}
|