|
public class MainActivity : Activity
{
SfDataForm dataForm;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
var form = new SfDataForm(this.ApplicationContext);
var layOut = FindViewById<LinearLayout>(Resource.Id.linearLayout1);
dataForm = new SfDataForm(this);
dataForm.AutoGeneratingDataFormItem += DataForm_AutoGeneratingDataFormItem;
dataForm.SourceProvider = new SourceProviderExt();
dataForm.RegisterEditor("IdCity", "Picker");
dataForm.DataObject = new Persons();
layOut.AddView(dataForm);
}
private void DataForm_AutoGeneratingDataFormItem(object sender, AutoGeneratingDataFormItemEventArgs e)
{
if (e.DataFormItem != null && e.DataFormItem.Name == "IdCity")
{
// Shown City Name in the Editor
(e.DataFormItem as DataFormPickerItem).DisplayMemberPath = "Name";
// Underlying property updated based on Id in Editors while changing the City Name
(e.DataFormItem as DataFormPickerItem).ValueMemberPath = "IdCity";
}
}
}
public class SourceProviderExt : SourceProvider
{
public override System.Collections.IList GetSource(string sourceName)
{
Cities city = new Cities();
var collection = new List<Cities>();
collection.Add(new Cities() { IdCity = 1, Name = "Newyork" });
collection.Add(new Cities() { IdCity = 2, Name = "Chennai" });
if (sourceName == "IdCity")
{
return collection;
}
return new List();
}
}
public class Persons
{
private int idCity;
private string name;
private int idPerson;
public int IdCity
{
get { return this.idCity; }
set
{
this.idCity = value;
}
}
public string Name
{
get { return this.name; }
set
{
this.name = value;
}
}
public int IdPerson
{
get { return this.idPerson; }
set
{
this.idPerson = value;
}
}
}
public class Cities
{
private int idCity;
private string name;
public int IdCity
{
get { return this.idCity; }
set
{
this.idCity = value;
}
}
public string Name
{
get { return this.name; }
set
{
this.name = value;
}
}
} |