Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Extend Datarow using IDataErrorInfo
 

Extend Datarow using IDataErrorInfo

I know there is a thread that is sorta named the same but the solution provided is of no use to me. I am using wpf , vb.net and framework 3.5

I have a typed dataset and i'd like to use IDataErrorInfo to take advantage of the validation stuff in the framework (even though it's not that great). Whenever I implement the interface I get a warning

"Default property 'Item1' conflicts with the default property 'Item' in the base class datarow. 'Item1' will be the default property."

Not sure exactly how to continue from here.
ThundR  Thursday, August 06, 2009 1:43 PM

Hi ThundR,

You said: I know there is a thread that is sorta named the same but the solution provided is of no use to me. Do you mean this thread:

http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/2367f061-4124-4050-8318-55193193c2d4?

In that thread, the answer provided the code snippet below:
partial class IPLDataSet

{

partial class CarRow

{

public bool validate()

{

if (CarId > 10)

{

SetColumnError("CarId", "Cannot be > 10");

RowError = "bugger!";

return false;

}

return true;

}

}

}

The code is in the .cs file. For example, if the typed dataset file is MyDBDataSet.xsd, the code is in file MyDBDataSet.cs, the automatically generated code is in file MyDBDataSet.Designer.cs.

IPLDataSet refers to the typed dataset name, in other words, the typed dataset class name. CarRow refers to the typed datarow class name. Validate is the added method to handle the data validating. In validate method, you can check the value of each property which is mapped to a column in a datarow. For example, if you need to restrict the value of CardId to less or equal than 10, you can check it and call SetColumnError and RowError to set the error. In conclusion, if we want to validate a custom DataRow, we only need to add a code snippet similar to above to the .cs file.

If the solution provided by the thread above cannot solve your issue, please let me know the reasons and your needs in detail, so that I can provide another solution for you.

Best regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, August 10, 2009 2:42 AM
You don't implement IDataErrorInfo.

The internal DataRowView which is ultimately bound under the scenes and thus the only object that really mattersalready implements this interface.

You control what error is reported through the DataRow RowError property and SetColumnError method.




BinaryCoder  Thursday, August 06, 2009 11:47 PM
Ok, so I create a ValidationRule and then I set the RowError prop or call SetColumnError based on what colum is bound?
ThundR  Friday, August 07, 2009 2:28 PM

Hi ThundR,

You said: I know there is a thread that is sorta named the same but the solution provided is of no use to me. Do you mean this thread:

http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/2367f061-4124-4050-8318-55193193c2d4?

In that thread, the answer provided the code snippet below:
partial class IPLDataSet

{

partial class CarRow

{

public bool validate()

{

if (CarId > 10)

{

SetColumnError("CarId", "Cannot be > 10");

RowError = "bugger!";

return false;

}

return true;

}

}

}

The code is in the .cs file. For example, if the typed dataset file is MyDBDataSet.xsd, the code is in file MyDBDataSet.cs, the automatically generated code is in file MyDBDataSet.Designer.cs.

IPLDataSet refers to the typed dataset name, in other words, the typed dataset class name. CarRow refers to the typed datarow class name. Validate is the added method to handle the data validating. In validate method, you can check the value of each property which is mapped to a column in a datarow. For example, if you need to restrict the value of CardId to less or equal than 10, you can check it and call SetColumnError and RowError to set the error. In conclusion, if we want to validate a custom DataRow, we only need to add a code snippet similar to above to the .cs file.

If the solution provided by the thread above cannot solve your issue, please let me know the reasons and your needs in detail, so that I can provide another solution for you.

Best regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, August 10, 2009 2:42 AM

You can use google to search for other answers

Custom Search

More Threads

• ComboBox and TextBox in DataGridView
• if statement in datagrid
• How to update an unbound datagrid/dataset?
• Data Transformation
• Can you set the column type in a bound grid
• DataGridView events master detail
• Big data updates
• DataBase Relationship Question?
• DataAdapter filling a DataTable with different number of records
• My data is not being saved to my database!