I need validation for the grid..
I am doing some thing like this
private TemplateColumn _TempCol = new TemplateColumn(); private TemplateColumn _TempDescription = new TemplateColumn();
Public View(){ _TempCol.Key = "ReportPropertyDto.Value"; _TempCol.Width = ColumnWidth.Auto; _TempCol.HeaderText = StringResource.ValueHeaderText; _TempCol.MinimumWidth = 100;
_TempDescription.Key = "CodeDescription"; _TempDescription.HeaderText = StringResource.DescriptionHeaderText; _TempDescription.Width = ColumnWidth.Auto; //_TempDescription.MinimumWidth = 137; _TempDescription.ItemTemplate = Resources["ColTextBlock"] as DataTemplate;
reportPropertiesValueGrid.Columns.Add(_TempCol); reportPropertiesValueGrid.Columns.Add(_TempDescription); reportPropertiesValueGrid.UpdateLayout();
}
private void Grid_InitializeRow(object sender, InitializeRowEventArgs e){
//here I add controls to the column based on the datatypeswitch (property.SQLDataType.ToLower()){
case "date": { _TempCol.ItemTemplate = Resources["ColDatePicker"] as DataTemplate; break; } case "varchar": { _TempCol.ItemTemplate = Resources["ColText"] as DataTemplate; break; }
In Xaml
my grid is bound to custom dto (say LocalDto)
<DataTemplate x:Key="ColText"> <TextBox Name="Textbox" Text="{Binding Path=LocalDto.Value, Mode=TwoWay,ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=Explicit}" HorizontalContentAlignment="Stretch" ></TextBox> </DataTemplate>
from the initilazeRow()
I am trying throwing error if validation for empty or null string fails
something like this
public void ValidateButtonTest(string value) { if(string.IsNullOrEmpty(value)) { throw new Exception("Required field."); } }
it throws an error.
I need to show red border to text box if validation fails
any help will be appreciated
Hi,
The validation in XamGrid could be achieved either by throwing an exception in your buisiness data object's property setter or either making you business object to implement IDataErrorInfo or INotifyDataErrorInfo interfaces. Looking at the sample code you have provided I assume the exception you are throwing is not in the property setter.
I am not quite sure what exactly you are trying to achieve but I suppose changing the Template Column's ItemTemplate in InitializeRow is not the best approach.
If you provide simplified version illustrating the scenario you are interested in I will be able to provide more help.
HTH
Thanks for the reply.. I did implement INotifyDataErrorInfo in buisness object and got it working