Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi, I have created custom property and bind it to xtragrid.column. Error provider for this property doesnt be shown when I save data. It works for other property (mapped to data) Any ideas? Thank you
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
Do you have the BusienssFieldDIsplayInEditorField attribute assigned to the custom property? <Browsable(False), _ BusinessFieldDisplayInEditor(), _ Description("My Custom Field"), _ DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _ Public property MyCustomField As String .... End Property
|
|
|
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 { // } }
|
|
|
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, 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
|
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, How to accomplish this? Sorry, still new to .NET. Thank you
|
|
|
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, ((System.ComponentModel.IDataErrorInfo)this)["ItemCode"] return empty string.
|
|
|
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.
|
|
|