- Home
- Forum
- Xamarin.Android
- Foreing Key
Foreing Key
Hi all,
I have doubts in the use of the component SfDataForm. In my case, one of the fields will be filled from another table as a foreign key.
For example, In the following scenary, I would have two tables in my database :
TABLE: Cities
- IdCitie – Int – Primary Key
- Name – String
TABLE: Persons
- IdPerson – Int – Primary Key
- Name – String
- IdCitie – Int – Foreing Key (Foreing Key for Cities)
I would like to utilize the component SfDataForm to show a form for Persons, but I would like the user choose the City(Cities in the Table) from my Cities Table, in another words: the user will visualize the name of the City, but the component will store the IdCitie.
Thank's.
Edison Jamir Benjamini
SIGN IN To post a reply.
3 Replies
SV
Srinivasan Vasu
Syncfusion Team
April 6, 2018 01:09 PM UTC
Hi Edison,
Thanks for contacting Syncfusion support.
We have checked your query and You can achieve your requirement using PickerEditor in SfDataForm.
We have prepared a simple sample based on your requirement. Please download the same from below location.
Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/DataFormApp1-561036986.zip
In this sample, we have two class as like table(Person and Cities). In PickerEditor, DisplayMemberPath property’s values will be shown as the PickerItems and the selected DisplaymemberPath property will update the corresponding ValueMemberPath property’s values in underlying Collection.
Please refer the below link to know more about PickerEditor:
Please refer the below code example
|
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;
}
}
} |
Regards,
Srinivasan
EJ
Edison Jamir
April 9, 2018 08:23 PM UTC
Hello Srinivasan,
I want to thank you for your help. I would like to inform that the code worked flawlessly. It was exactly what I needed.
More questions would be:
- The form "picker" showed can be bigger (heigth and width)?
- The form "picker" can have incremental search?
Thank's.
Edison Jamir Benjamini
SV
Srinivasan Vasu
Syncfusion Team
April 12, 2018 12:30 PM UTC
Hi Edison,
Sorry for delay caused.
Regarding customizing Picker size and add incremental search.
As per implementation of picker editor size cannot be customized by directly and also search option support is not available in Picker editor of SfDataForm.
Regards,
Srinivasan
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
EJ Edison Jamir
- Apr 5, 2018 12:48 PM UTC
- Apr 12, 2018 12:30 PM UTC