How to know programmatically if the grid has any error in Silverlight GridDataControl?
GridDataControl enables you to get the error info for each cell using QueryCellInfo event. The HasErrorInfo property indicates you whether the particular cell has any error information or not. When the cell has any error you can use ErrorInfo property to get the error information of that particular cell. Refer the following code snippet.
C#
dataGrid.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(OnQueryCellInfo); void OnQueryCellInfo(object sender, GridQueryCellInfoEventArgs e) //to get error info { if (e.Style.HasErrorInfo) Console.WriteLine(e.Style.ErrorInfo); else Console.WriteLine("No errors"); }
Here, you can check whether the cell has any error using “HasErrorInfo”. When there is any error, an ErrorInfo displays in the output window, else “No errors” displays in the output window.
Other properties related to ErrorInfo are given as follows.
Property Name | Return Type | Description |
HasError | boolean | Checks whether any Error has been initialized for the current object. |
Error | string | Contains error information when a text could not be converted to the type specified with CellValueType. |
HasErrorAlertText | boolean | Checks whether the current object has any error alert text. |
ErrorAlertText | string | Gets or sets the error alert text. Holds the error alert text when importing the excel file to grid. |
HasErrorAlertTitle | boolean | Checks whether the current object has any error alert title. |
ErrorAlertTitle | string | Gets or sets the error alert title. Holds the error alert title while importing the excel file to grid. |