Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
It will work if your custom field has a field within the DataTable in the BO. If you have a custom property that does not pull from the internal data table of the BO then it will not return an error. The same applies for the broken rule. So at present, without having another object, you would have to add the field to the SELECT or manually to the data table using the Columns collection of the CurrentDatatable. Once the field exists, then you can just add a broken rule: Me.AddBrokenRule("MyCustomField", "My Error")
|
|
|
Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi,
How could I make control response to IDataErrorInfo for custom field?
Thank you
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
Here's the code for the IDataErrorInfo.Item get: '-- Return the error for the given field If Me.BrokenRules.Contains(Me.CurrentRowIndex, columnName) Then Return Me.BrokenRules(Me.CurrentRowIndex, columnName).Description ElseIf Me.CurrentDataTable.Columns.Contains(columnName) Then Return Me.CurrentRow.GetColumnError(columnName) Else Return String.Empty End If So, if the BrokenRules collection has an entry for the current row and "ItemCode", then it will return the description in the broken rule. Otherwise, it checks the underlying DataTable for errors, then just returns an empty string. Since your custom field does not exist as a column, the second condition will never be hit, so you have to verify that the broken rule is being added properly. You can use the ToArray() method on the BrokenRules to see all of the rules in the collection and make sure that you're rule is in there for the "ItemCode" property.
|
|
|
Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi, ((System.ComponentModel.IDataErrorInfo)this)["ItemCode"] return empty string.
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
When the IDataErrorInfo interface returns the error for the specified column in the BusinessLayer class, it first checks the BrokenRules collection to see if there is a broken rule for the specified field, then it checks the underlying DataTable for errors on the column. What you need to do is put a break point in your CheckRulesOnCurrentRow() method and check the value of ((System.ComponentModel.IDataErrorInfo)this)["ItemCode"] If the value of this is an empty string, then the implementation of the IDataErrorInfo.[this] property is not returning properly; however, if it returns a value, then the grid is not properly displaying the error provider. Let me know which one it is.
|
|
|
Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi, How to accomplish this? Sorry, still new to .NET. Thank you
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
It is because the custom property is not set in error. For example, when using ADO.NET, you can set the underlying column in error by calling the ADO.NET SetError method which will then interface with the error provider. If you create an error provider, you can see how it interfaces with a property or a bound item when dealing with an error. In this case, the actual bound field is not actually being set in error because there is not an underlying field in the ADO.NET table more than likely.
|
|
|
Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi, I have code in checkrulesoncurrentrow() as below. I debug the code and found it run properly. Just that the error provider not shown when save. private void ReturnNoteDetailsBO_CheckRulesOnCurrentRow(CheckRulesEventArgs e) { if (this.ItemCode == null || this.ItemCode.Length == 0) { this.AddBrokenRule("ItemCode", this.ErrorProviderRequiredFieldDesc); } }
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
More than likely your custom property is not set in error then. You will have to set the column in error before it will show an error provider for that field.
|
|
|
Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi, Yes, I did [Description("Item Code"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false), MicroFour.StrataFrame.UI.Windows.Forms.BusinessFieldDisplayInEditor()] public System.String ItemCode { get { SqlCommand loCommand = new SqlCommand(); loCommand.CommandText = "Select ItemCode FROM Items WHERE ItemID = @lcItemID"; loCommand.Parameters.Add("@lcItemID", SqlDbType.UniqueIdentifier); loCommand.Parameters["@lcItemID"].Value = this.ItemID; return (System.String)this.ExecuteScalar(loCommand); } set { // } }
|
|
|