Hi,
Just wondering if how to change the spinner increments for a DateTime column in a WinGrid? At the moment it defaults to a single minute - I'd like it to increment 15 minutes at a time - and not just cycle the minutes but increment the hours as required. Is there a way I can capture the spinner button press and manually alter the value?
Thanks in advance,
Scott
Hi Scott,
The spinning is context sensitive. Do it depends on the location of the cursor. If the cursor is in the minute section, it spins a minute at a time. If it's in the hour section, it spins an hour at a time.
There's no way to change the incremement when using the built-in spinner. But you can do what you want using an editor. Put an UltraDataTimeEditor on the form with your grid. Don't set SpinButtonDisplayStyle. Use the ButtonsRight collection and add a SpinEditorButton.
Set the grid column's EditorContorl to the UltraDateTimeEditor.
Unlike the built-in spin button, this button does nothing by default. You have to code it using by handling the EditorSpinButtonClick event of the UltraDateTimeEditor. Use e.Context in this event to determine the Cell of the grid which is being spun.
Beautiful! Works like a charm.
Thanks for your help.
I have same requirement and unable to figure out how i can do this, can you please post example or code snap which worked for you?
Here's a quick sample I whipped up.
WindowsFormsApp19.zip
Thanks for quick reply, I review your sample, this I am able to manage but I am looking for something like below:
I have two columns like “Start Time” and “End Time” like below
If my select hours section it should increment by an hour if I select minute section it should increment by 15 minutes. In your sample it by default increment with 15 minutes.
If I use UltraDateTimeEditor outside Grid and change Spin Increment on MouseDown Event of UltraDateTimeEditor like below then it work completely fine but when I set the this control in EditorComponent the mouse down event is not firing.
private void dateTimeEditor_MouseDown(object sender, MouseEventArgs e)
{
if (sender is UltraDateTimeEditor ultraDateTimeEditor)
var element = ultraDateTimeEditor.UIElement.ElementFromPoint(e.Location);
while (element != null)
if (element is SectionUIElement sectionElement)
if (sectionElement.Section is MinuteSection)
ultraDateTimeEditor.SpinIncrement = new DateTimeIncrement(0, 0, 0, 0, 5, 0, 0);
}
else if (sectionElement.Section is HourSection)
ultraDateTimeEditor.SpinIncrement = new DateTimeIncrement(0, 0, 0, 1, 0, 0, 0);
break;
element = element.Parent;
Can you help why Mouse down event is not fired when set with EditorComponent in grid?
Or is there a way this can be achieve?
Thank you in advance.
Thank you Mike, appreciate all your help.
MinWidth, MaxWidth is working for me. this is what i was looking for. all set.
AutoSizeMode is not related to the size of the grid. That has to do with auto-sizing the width of the column to the contents of that column. The property you want here is grid.DisplayLayout.AutoFitSyle. In any case, what you can do is set MinWidth, MaxWidth, and Width to the same value on the columns you want to remain a fixed size - and then those columns will honor those settings when the grid AutoFit's the columns.
Hi Mike,
Thank you for all your help. I am all set for this issue.
Everything is working as expected now. We can close this thread marking as answered.
I have another question in general not related to this issue but for Ultragrid Dock = Fill.
I have UltraGrid placed in Panel with _grdDefinitions.Dock = DockStyle.Fill;
I have total 5 columns like below:
Start Time | End Time | Column 3 | Column 4 | Column 5
When i maximize my form all the columns are auto resized which is fine but i want Start Time and End Time columns to be fixed size and not resized automatically when form maximized, is there a way i can make this?
I tried grid Resize event and setting again width but did not work.
Also i tried colStart.AutoSizeMode = ColumnAutoSizeMode.None; but that also not worked.
I don't think -1 is a valid value for either SelectionStart or SelectionLength. You could try 0.
But I think there's a better way. Try setting CellClickAction on the column:
dateTimeColumn.CellClickAction = CellClickAction.Edit;
The default is CellClickAction.EditAndSelectText. So CellClickAction.Edit will place the caret wherever the user clicks. That only works when CLICKING on the cell, of course. If the user tabs into the cell, it still selects all of the text. So you could handle that like so:
private void UltraGrid1_AfterEnterEditMode(object sender, EventArgs e) { var grid = (UltraGrid)sender; var activeCell = grid.ActiveCell; var cellEditor = activeCell.EditorResolved; cellEditor.SelectionLength = 0; }
Notice that I am setting SelectionLength here, but NOT SelectionStart, because if I did that, you would lose the position of the caret when clicking on the cell.
I figured out AM/PM stuff same way you mentioned after I posted my reply.
This is working like a charm.
Thank you again for all your help, suggestions and quick replies.
Only one thing is when I click on Cell to Edit, by default it select all the text, just wanted to know is there a way I can unselect the default selected text and just keep caret at the place user clicked to edit?
I tried capturing UltraGrid1_AfterEnterEditMode event and setting below two properties to -1, and it unselect everything but it bring caret at 0th position up on edit mode, I was looking to keep caret where user click to edit, for e.g if user first click at minutes section to edit the cell then caret should be at minute section initially. Can you please see is there a way we can achieve this?
cellEditor.SelectionStart = -1;
cellEditor.SelectionLength = -1;