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.
Hi Mike,
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;
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.
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.
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.
Thank you Mike, appreciate all your help.
MinWidth, MaxWidth is working for me. this is what i was looking for. all set.