|
1 | | -# editable-drop-down-dataform-xamarin |
2 | | -How to make editable drop down in Xamarin.Forms DataForm (SfDataForm) |
| 1 | +# How to make editable drop down in Xamarin.Forms DataForm (SfDataForm) |
| 2 | + |
| 3 | +You can make the editable drop down in Xamarin.Forms SfDataForm by using custom editor. |
| 4 | + |
| 5 | +You can create and add custom editor to SfDataForm by overriding the DataFormEditor class, where the CustomDropDownEditor is inherited using the DataFormDropDownEditor . |
| 6 | + |
| 7 | +Refer to the online user guide documentation for creating new custom editor in DataForm. |
| 8 | + |
| 9 | +**C#** |
| 10 | + |
| 11 | +DropDownEditor modified by customizing DataFormDropDownEditor. |
| 12 | + |
| 13 | +``` c# |
| 14 | +public class CustomDropDownEditor : DataFormDropDownEditor |
| 15 | +{ |
| 16 | + public CustomDropDownEditor(SfDataForm dataForm) : base(dataForm) |
| 17 | + { |
| 18 | + } |
| 19 | + protected override void OnInitializeView(DataFormItem dataFormItem, SfComboBox view) |
| 20 | + { |
| 21 | + base.OnInitializeView(dataFormItem, view); |
| 22 | + view.IsEditableMode = true; |
| 23 | + } |
| 24 | +} |
| 25 | +``` |
| 26 | +Refer to the following code example for binding DataObject and register the editor using RegisterEditor as CustomDropDownEditor to make data form items as custom editor in DataForm. |
| 27 | + |
| 28 | +**C#** |
| 29 | + |
| 30 | +DropDown editor registered to DataForm. |
| 31 | +``` c# |
| 32 | +namespace DataFormDropDown |
| 33 | +{ |
| 34 | + public class DataFormBehavior : Behavior<ContentPage> |
| 35 | + { |
| 36 | + SfDataForm dataForm; |
| 37 | + protected override void OnAttachedTo(ContentPage bindable) |
| 38 | + { |
| 39 | + base.OnAttachedTo(bindable); |
| 40 | + dataForm = bindable.FindByName<SfDataForm>("dataForm"); |
| 41 | + dataForm.DataObject = new Address(); |
| 42 | + dataForm.RegisterEditor("DropDown", new CustomDropDownEditor(dataForm)); |
| 43 | + dataForm.RegisterEditor("Country", "DropDown"); |
| 44 | + } |
| 45 | + } |
| 46 | +} |
| 47 | +``` |
| 48 | +**Output** |
| 49 | + |
| 50 | + |
0 commit comments