How to validate a ComboBox programatically?
Posted
by
PhOeNiX
on Stack Overflow
See other posts from Stack Overflow
or by PhOeNiX
Published on 2012-06-07T04:37:41Z
Indexed on
2012/06/07
4:40 UTC
Read the original article
Hit count: 303
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;
© Stack Overflow or respective owner