How to validate a ComboBox programatically?
- by PhOeNiX
How can i validate a ComboBox for null entry? My combobox is in a model as i am generating it dynamically. Now what i want is that when the the columns are generated dynamically, the border of combobox should be red as no value is selected and once the value is selected the border shud become normal. The following is my combobox in model :
DataGridTemplateColumn dataGridComboBoxTemplateColumnObj = new DataGridTemplateColumn();
dataGridComboBoxTemplateColumnObj.Header = column.Header;
FrameworkElementFactory comboBoxFactory = new FrameworkElementFactory(typeof(ComboBox));
Binding bindingItemSourceObj = new Binding(column.ItemsSourcePropertyName);
comboBoxFactory.SetValue(ComboBox.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
comboBoxFactory.SetValue(ComboBox.ItemsSourceProperty, bindingItemSourceObj);
comboBoxFactory.SetValue(ComboBox.SelectedValuePathProperty, column.ValuePropertyName);
dataGridComboBoxTemplateColumnObj.CellTemplate = new DataTemplate();
dataGridComboBoxTemplateColumnObj.CellTemplate.VisualTree = comboBoxFactory;