Hello.
I know that the MinValue and MaxValue can be set on a column level, but how do you set it on a cell level?
I've managed a workaround by setting those properties on the column in the "BeforeEnterEditMode" event, but I'm not sure that that's the best way (see code, below).
Is there a better way?
Thanks in advance,
Mike
ugIncludedItems.BeforeEnterEditMode
ugIncludedItems.ActiveCell.Column.MaxValue =
).Value)
ugIncludedItems.ActiveCell.Column.MinValue = 0
Sub
I was able to get this working in our scenario using the approach of setting values on an editor for each cell in the InitializeRow event.
In our scenario we had a date where we'd want to let people pick the next date if the time was within 1 hour of midnight. Inside our InitializeRow event, I put code like this:
var rowObject = e.Row.ListObject as OurModelType; if (rowObject == null) return; var dateColumn = e.Row.Cells["EventDate"]; if (rowObject.EventTime.Hour >= 23) { dateColumn.Activation = Activation.AllowEdit; dateColumn.EditorComponent = new UltraDateTimeEditor { MinDate = rowObject.EventDate, MaxDate = rowObject.EventDate.AddDays(1) }; } else { dateColumn.Activation = Activation.NoEdit; }
Nevermind, Mike. I had the "AcceptButton" property set on a button on the form. When I removed it the Enter key raised the event.
Now I have to figure out how to get around that.
Mike,
I wasn't too crazy about changing the Min/Max on the column. I'll have to rethink it.
On the second question, the Enter key isn't firing either event (KeyDown or KeyPress).
I have breakpoints set and they are not hit when I press Enter, though every other key raises the events.
What gives?
Thanks,
Hi Mike,
milop said:What are any ill effects of the code I posted in my first post and
I'm not sure there's anything terribly wrong with it. But you should be aware that you are setting the MinValue and MaxValue on the entire column and not just the one cell. I'm not sure if it ever happens, but it's not entirely unreasonable that another cell in another row might get validated for some reason and at that point, the MinValue and MaxValue of the column would be incorrect. Like I said, I'm not sure if that ever happens - I don't think any non-active row will be validated by the grid, but it's something to keep in mind.
I'm also not thrilled about using BeforeEnterEditMode for this. I'd probably use BeforeCellActivate or even BeforeRowActivate, just to be safe.
milop said:What do I need to do to enable the Enter key to trigger the update? Right now the user has to leave the row in order for this to occur.
Trap the grid's KeyDown or maybe KeyPress and then you can commit the changes to the current active row like this:
grid.PerformAction(ExitEditMode)
grid.ActiveRow.Update()
Hi, Mike. Thanks for the response.
The columns in question use "IntegerNonNegativeWithSpin" as the style and I was hoping to prevent users from spinning past the min/max. I do, however, use the BeforeCellUpdate to do exactly what you suggested for validation (just in case).
Two questions:
Thanks again,