Hello,
I am using an editor to set the min/max values of cells within my ultra grid, but now I must obtain these values in a cell event in order to check the user input and make sure it does not go lower/higher than the min/max values that I had set.
Is there a way to do this? Thank you in advance,
-Emma
Hi Emma,
I recommend using the column itself to set the min and max values. If you set it this way, the grid will automatically handle checking that the user inputs valid values.
ultraGrid1.DisplayLayout.Bands[0].Columns["Column 0"].MinValue = 1;ultraGrid1.DisplayLayout.Bands[0].Columns["Column 0"].MaxValue = 100;
Please try this out and let me know whether it works for you.
Hi Mike,
Unfortunately, I need to set different min/max values for each cell, so using the columns won't work in my case.
You can use the BeforeCellUpdate event for this. In this event, you could compare the new value to the minimum and maximum values for that cell. If the value doesn't fall in the range, you can cancel the event and alert the user.
How you get the min and max values would depend on your specific implementation. Most likely, you will get the editor from the cell and cast it to the type of editor you expect.
If you can provide some sample code that shows how you are setting up the editors and your min/max values, I can give a more specific answer.
I am currently creating and setting a new editor for each cell in my grid through the initialize row event. Here is a simplified version of my method:
private void grid_InitializeRows(object sender, InitializeRowEventArgs e) { DefaultEditorOwnerSettings settings = new DefaultEditorOwnerSettings(); DefaultEditorOwner owner = new DefaultEditorOwner(settings); EmbeddableEditorBase editor = null; UltraGridCell gridCell = null; if (e.Row.Cells["Number"].Value == 1) //Specific row { gridCell = e.Row.Cells["ColumnName"]; settings = new DefaultEditorOwnerSettings(); owner = new DefaultEditorOwner(settings); settings.MaskInput = "nn.nnnn"; settings.Format = "##.####"; settings.MinValue = 40; settings.MaxValue = 60; editor = new EditorWithMask(owner); gridCell.Editor = editor; } else if (e.Row.Cells["Number"].Value == 2) { gridCell = e.Row.Cells["ColumnName"]; settings = new DefaultEditorOwnerSettings(); owner = new DefaultEditorOwner(settings); settings.MaskInput = "n.nnnn"; settings.Format = "0.####"; settings.MinValue = 0; settings.MaxValue = 5; editor = new EditorWithMask(owner); gridCell.Editor = editor; } }
My question was more of how I can access the min/max values after I had already set it in the cell editor.
I figured it out though, I used the following code:
Decimal maxValue = Convert.ToDecimal(grid.ActiveCell.Editor
.DefaultOwner.GetMaxValue(grid.ActiveCell));
And since I am using a mask input, the ranges are checked automatically through the CellDataError event.
Thanks,
Emma
You should be able to use the grid's BeforeExitEditMode event to capture this user action. You can check ultraGrid1.ActiveCell.Value to see the current text (before edits) and you can check ultraGrid1.ActiveCell.Editor.CurrentEditText to see what the user typed in.
Please let me know if you have any further questions.