Hello, I have a grid whose data source is a business entity, ie BindingList . I want to validate user inputs for all cells in the row(s) for that grid. I want to use the approach listed at http://help.infragistics.com/Help/NetAdvantage/NET/2008.2/CLR2.0/html/WinGrid_Display_Row_Cell_Errors_Using_IDataErrorInfo.html but the issue is that in my case the e.Row.ListObject returns a BidingList . , whereas the example in this link expects a DataRowView . How did you resolve it in ur case, as you also had a business entity and not a DataRowView . Pls advice. Is there any other better approach for it ? using fragistics UltraValidator control, custom coding for cellupdate events, etc.
Thanks....
Your ListObject is returning a BindingList? That doesn't make any sense unless every row in your list is another list, in which case, I'm not sure that the grid would even be able to display it.
Based on your other post, it sounds like your ListObject should be returning some custom object (a Person class in your other example). In which case, your Person class would have to implement IDataErrorInfo in order for you to use the DataErrorInfo support in the grid.
Hi Mike,Thanks for you reply.
Can you provide me a sample of what requries to be done. I understand that i need to implement the IDataErrorInfo interface in my class.Where i get stuck at is at:DataRowView drv = (DataRowView)e.Row.ListObject(refer to http://help.infragistics.com/Help/NetAdvantage/NET/2008.2/CLR2.0/html/WinGrid_Display_Row_Cell_Errors_Using_IDataErrorInfo.html )It throws me an error that a class object (e,g Person obj) was returned whereas we require a DataRowView.
Pls guide me as to how i go about it?Thanks,Sumit
Hi Sumit,
The ListObject of a grid row represents the object in the DataSource for that row. The ListObject property returns an object, because the grid does not know what type it is. A DataRowView is the type that A DataSet or DataTable will use, but since you are not using either of those types are you data source, the ListObjects in your grid will not be of this type - they will be of whatever type you are using for the rows in your data source.
So to get the ListObject in your case you would have to do something like this:
Person person = (Person)e.Row.ListObject
But I'm not sure why you would need to do this, anyway. If you simply implement IDataErrorInfo on the Person class, the grid would take it from there.
Hi Ashish/Sumit,
I got the same problem in my project. I have used a different approach but your and Mike's idea is good and easy to implement ( I was thinking about this scenarion on teh beginning of my project but always is BUT ).
I have found in the Internet one website which explains how to implements Mikes idea, let's take a look.
Code 1:
using System.ComponentModel;
public class NoteInfo : System.ComponentModel.IDataErrorInfo {
//...
//Stores error descriptions for the Day, Month, Year and NoteID properties
Hashtable propertyErrors;
//Stores an error description for the item
string noteError;
public NoteInfo(int _noteID, int _day, int _month, int _year) {
//Set errors to empty strings
propertyErrors = new Hashtable();
propertyErrors.Add("Day", "");
propertyErrors.Add("Month", "");
propertyErrors.Add("Year", "");
propertyErrors.Add("NoteID", "");
noteError = "";
}
public int NoteID { /*...*/ }
public int Day { /*...*/ }
public int Month { /*...*/ }
public int Year { /*...*/ }
//Gets and sets an error for the current item
internal string NoteError {
get { return noteError; }
set {
if(noteError == value) return;
noteError = value;
OnNoteChanged();
public void ClearErrors() {
SetColumnError("Day", "");
SetColumnError("Month", "");
SetColumnError("Year", "");
NoteError = "";
//Sets an error for an item's property
public void SetColumnError(string elem, string error) {
if(propertyErrors.ContainsKey(elem)) {
if((string)propertyErrors[elem] == error) return;
propertyErrors[elem] = error;
//Gets an error for an item's property
public string GetColumnError(string elem) {
if(propertyErrors.ContainsKey(elem))
return (string)propertyErrors[elem];
else
return "";
//The owner collection
internal ProjectNotes Owner { /*...*/ }
//Notify the owner collection about record changing
protected void OnNoteChanged() {
if(Owner != null)
Owner.OnRecordChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
Owner.IndexOf(this)));
#region IDataErrorInfo Members
//Returns an error description set for the item's property
string IDataErrorInfo.this[string columnName] {
get {
return GetColumnError(columnName);
//Returns an error description set for the current item
string IDataErrorInfo.Error {
#endregion
Code 2:
public class ProjectNotes: CollectionBase, IBindingList {
//Adds a new item to the collection
public int Add(NoteInfo nInfo) {
int index = List.Add(nInfo);
return index;
//Fires the IBindingList.ListChanged event.
protected internal void OnRecordChanged(ListChangedEventArgs e) {
if(ListChanged != null) ListChanged(this, e);
#region IBindingList Members
// ...
Code 3:
//Returns the name of the date property containing invalid data
private string IsValidDate(int day, int month, int year) {
if(month < 1 || month > 12) return "Month";
if(day < 1 || day > DateTime.DaysInMonth(year, month)) return "Day";
if(year < 1980 || year > 2010) return "Year";
private void ValidateData() {
ProjectNotes notes = gridControl1.DataSource as ProjectNotes;
foreach(NoteInfo nInfo in notes) {
string valid = IsValidDate(nInfo.Day, nInfo.Month, nInfo.Year);
nInfo.ClearErrors();
if(valid != "") {
nInfo.NoteError = "Check the date";
nInfo.SetColumnError(valid, "Invalid " + valid);
I think you need to change NoteError to RowError and you will be like in Mike's explenation. Also constructor needs to be changed but I think it is a good example of code how to implement IDataErrorInfo interface.
I am trying to implement this proposal but I got strange behaviour on my grid. Instead of selecting one cell I am ending with whole row selected because of wrong entry. Maybe you will find why ( faster then me ) . Let me know if this code is working for you and you got any others ideas how to sole this inconvenience. Regards Piotr
Yes, that is precisely what I mean. The grid has built in support for IDataErrorInfo, and it looks for this information on the data objects in the data source. This is how it works when you bind to a DataTable. The DataTable provides the grid with a list of DataRowView objects. Each one represents a row of data and implement IDataErrorInfo.
Hi Mike,Do you mean that after implementing the interface, i will be able to use :
Person.RowError = rowError;Person..SetColumnError("columnname", cellError);