Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1105
Cell edit selects existing text
posted

Currently I have a column in an UltraGrid.  The CellClickAction is set to CellClickAction.Edit and the CellActivation is set to Activation.AllowEdit.

On double click of the cell (say I have one  cell active in the grid and I immediately double click to another editable cell), I want to mimic the behavior of Excel by doing the following:

1) Activate cell and have it enter edit mode.

2) If data exists in the cell, place the cursor within the data at the point where the double-click was performed.

I've successfully made the first part happen by hooking into the MouseDoubleClick event and calling .PerformAction(UltraGridAction.EnterEditMode).

However, what I see is that when the cell enters edit mode, the existing cell data is selected (and any new non-control key press clears this data and the next key is character 1). 

Using the following code I can clear the text selection:

              EmbeddableEditorBase editor = cell.EditorResolved;

              if (editor.SupportsSelectableText)
              {
                editor.SelectionStart = 0;
                editor.SelectionLength = 0;
              }

But that still doesn't get me what I'm looking for, setting the cursor where the double click occurred.

My questions are:

1) Is the immediate selection of text when entering edit mode (if text exists) a default UltraGrid behavior? And If so, is there a way to disable this?

2) Is there a way to achieve my behavior of setting the cursor at the double click location?

 

Thanks in advance.

 

Chris Rowland

Parents
No Data
Reply
  • 469350
    Suggested Answer
    Offline posted

    Hi Chris,

    I'm afraid you lost me.

    puckstopper_37 said:
    I've successfully made the first part happen by hooking into the MouseDoubleClick event and calling .PerformAction(UltraGridAction.EnterEditMode).

    If CellClickAction is set to edit, then you do not need to write any code to get the cell to enter edit mode on a double-click. A double-click includes two clicks. So the first click on the cell will put it into edit mode without calling any code of yours. And in fact, the cell will already be in edit mode before the MouseDoubleClick event fires. So it seems to me that unless there's some other factor at work here, this code will do nothing.

    In addition, the grid already has code in place so that when you click (single click) on a cell, the caret will be placed at the point where the mouse cursor is.

    Double-clicking on a cell will automatically put that cell into edit mode and select all of the text. This is pretty standard Windows behavior.

    I'm pretty sure that the way it works in Excel is that the first click selects the cell and does not enter edit mode. And the second click (which need not neccessarily be fast enough to qualify for a double-click) enters edit mode and places the caret at the clicked point.

    Having said all that, I don't see any way to get this to happen without some pretty tricky coding. You can easily get the first part by setting CellClickAction to CellSelect.

    And you could trap for a MouseDown or MouseUp event on the grid and determine which cell was clicked and enter edit mode if that cell was already selected.

    But determining where to place the cursor is the hard part. I'm pretty sure that what the grid does is enter edit mode on the cell, then get's the TextBox control that is displayed over the grid and uses unmanaged code to call SendMessage to sound a MouseDown and/or a MouseUp to the TextBox control at the same point to simulate a mouse click at that point to place the cursor.

     

     

Children
No Data