There are some columns in the ultragrid(in winform), one column is POQty and the other column is RecQty, and they must be positive number,Now after input the value in the RecQty column,if the value of RecQty is greater than the value of POQty,then show a warning message .
By the way, is there a property of ultragrid to set the column only accept postive number?
Many thanks
I guess it depends on what your wingrid’s data source is to go about this. Assuming you were using an ADO data table as the wingrid’s datasource, I would create a validation method that hooks into the data table’s row changed event to check and see if the RecQty column value is greater than the POQty column value and then if necessary use the data row’s Set Column Error method with the error message. But in order for the gird to display the message you have to make sure to set the wingrid’s SupportDataErrorInfo property to CellsOnly or RowsAndCells else the grid will ignore the error information.
If you are trying to do something simple then you can just use the grid’s AfterRowUpdate event and then examine the two columns and respond appropriately.
You can prevent the user from entering negative numbers using the wingrid designer going to the appropriate band and columns section. Each column has a MaskInput property that you can set. The mask will for the user to enter information in the format you specify. Alternatively, you can use something like the Numeric Editor control and set it's mask to not allow negatives and then set the wingrid column's EditorControl property to that control and the cell will effectively host the specified control as the editor.
How does that sound?
Depending on what kind of "warning message" you want to show, you might want to use InitializeRow, instead of AfterCellUpdate. AfterCellUpdate is good if you want to show a MessageBox. If you want to warn the user using a color or an image in the cell, then InitializeRow would be better.
Also, there's a property on the column called Style that you can use to prevent negative numbers for certain numeric types. You can also use the mask, but Style is simpler, as it's an enum.
Still another option would be to use the UltraWinValidation component.
I was thinking more along the lines of catching the change the user has made after the cell value has changed. Doesn't the InitializeRow event only fire as the rows are being populated in the grid?
I didn't know about the style property... very nice. Learn something new every day.
Steve Smith said:Doesn't the InitializeRow event only fire as the rows are being populated in the grid?
This event is specifically designed to do things like coloring a row or cell based on a value in the cell. As such, it fires any time any cell value in the row changes.
So InitializeRow would not be a good event to use if you plan to show a MessageBox, for example. But it's great if you want to color the cell or apply an image to it.
Ah... I see. You are a wealth of infra knowledge.
thanks all !