Is there a simple way to add to the add items to a sfDataForm ComboBox?
Here is how I load a non-DataForm ComboBox:
private void LoadComboBoxes()
{
visitcategory = new ObservableCollection<string>();
visitcategory.Add("--Select One--");
visitcategory.Add("Office Visit");
visitcategory.Add("Established Patient");
visitcategory.Add("New Patient");
visitcategory.Add("Health and Behavioral Assessment");
visitcategory.Add("Preventative Care Services");
visitcategory.Add("Ophthalmological Services");
VisitCategoryComboBox.ItemsSource = visitcategory;
VisitCategoryComboBox.SelectedIndex = -1;
}
Hi Frederick,
Thank you for reaching out. To achieve your requirement, you can load the combo box using the `ItemSourceProvider`. Register the property as a `ComboBox` using the `RegisterEditor` method to make the editor function as a combo box editor, as shown in the code snippet below:
|
public string Country { get; set; }
dataForm.RegisterEditor("Country", DataFormEditorType.ComboBox); dataForm.ItemsSourceProvider = new DataFormItemsSourceProvider();
public class DataFormItemsSourceProvider : IDataFormSourceProvider { public object GetSource(string sourceName) { if (sourceName == "Country") { List<string> list = new List<string>() { "USA", "Japan", "UK", };
return list; }
return new List<string>(); } }
|
We have prepared a simple sample demonstrating this. Please see the attached sample for your reference.
If you have any further questions or need assistance, please let us know!
Regards,
Vidyalakshmi M.
Thank you for that sample, but I'm looking for a solution that does not include the multiple Folders etc.
My dataform has a number of properties that I want to make into comboboxes.
<dataform:SfDataForm
x:Name="usersDataForm"
AutoGenerateItems="True"
GenerateDataFormItem="usersDataForm_GenerateDataFormItem"
ValidateProperty="usersDataForm_ValidateProperty" />
I want to make the suffix field a combo box for "Jr., Sr.II ) and the Specialty field (DR., Nurse,Therapist)
Hi Frederick,
Regarding your queries:
Handling Events in Code-Behind: Yes, you can manage the events and behavior of the DataForm directly in the xaml.cs file without the need for a separate behavior class.
Identifying "DataForm Generated" Fields: When the `AutoGenerateItems` property is set to `True`, editors are automatically generated based on the property type. To identify these generated editors, you can utilize the `GenerateDataFormItem` event, which is triggered for each editor creation. The `GenerateDataFormItemEventArgs` provides information about the currently generated editor.
Making Suffix and Specialty Fields ComboBoxes: To convert the `Suffix` and `Specialty` fields into ComboBoxes, you can register them as ComboBox editors using the `RegisterEditor` method. You can then populate these ComboBoxes by providing the itemsource in the `ItemSourceProvider` class as shown in the code snippet below.
|
this.dataForm.ItemsSourceProvider = new DataFormItemsSourceProvider(); this.dataForm.RegisterEditor("Suffix", DataFormEditorType.ComboBox); this.dataForm.RegisterEditor("Speciality", DataFormEditorType.ComboBox);
public class DataFormItemsSourceProvider : IDataFormSourceProvider { public object GetSource(string sourceName) { if (sourceName == "Suffix") { List<string> list = new List<string>() { "Jr.", "Sr.", };
return list; }
if (sourceName == "Speciality") { List<string> list = new List<string>() { "DR.", "Nurse", "Therapist", };
return list; }
return new List<string>(); } }
|
We have prepared a sample according to these suggestions. Please find the attached sample for your reference.
If you require further assistance, feel free to let us know.
Regards,
Vidyalakshmi M.