Ticket Q298211
Visible to All Users

Focused Cell should automatically open Editor

created 14 years ago

Hey guys
I have a GridView in my WinForms application.
Some of the columns of this view are set with AllowEdit = False. Most do not.
Let's say we have Columns A through to E. Column C has AllowEdit = False. The others don't.
I start in Column A - I left click in. The editor automatically opens. I enter my value and press Tab.
Control flows to Column B. The editor automatically opens. I enter my value and press Tab.
Control flows to Column C. The editor does not open (I can AutoFilter this column if I so choose). I press Tab/
Control flows to Column D. *The editor does not open automatically*. I press Tab.
Control flows to Column E. *The editor does not open automatically*.
I want the behaviour of tabbing-in to D and E to be that the editor will automatically open.
I have previously implemented this by binding to the FocusedColumnChanged event. Within that event I was calling this.gridView.ShowEditor(). This worked, but led to further problems.
I *also* need to have the text in the editor be automatically selected whenever a user selects the cell in question. I have set EditorShowMode to MouseUp and AutoSelectAllInEditor to True.
My implementation above of binding to the FocusedColumnChanged event effectively breaks the select-all behaviour when I select into a column using the mouse.
I need some method of getting both behaviours right all the time.
Any help in the right direction would be greatly appreciated.

Show previous comments (3)
DS DS
Daniel Schealler 14 years ago

    For context: I'm not overly attached to the use of spin edit controls. The reson for their use is historic - in the original cut of our product we had a requirement for up/down buttons in our fields.
    That has since been cut - it was distracting the users, the majority of whom are mostly interested in keyboard input. We just suppressed the display of the up/down buttons of the spineditor and carried on.
    Our requirements for these fields are:

    1. Only accept integer or (alternatively) floating-point values (up to 3 decimals)
    2. Allow for custom formatting (1.05 becomes -> 1.05 kg on display)
      That's it.
      Obviously I'd like to just stick to the spin editors because until now that's been less work. However, if a change to a different control is the only avaliable solution at the moment then I would be open to that.
    Stan (DevExpress Support) 14 years ago

      Hi Daniel,
      Thank you for the additional information. I have found a mistake in my code. The problem is caused by the fact that the editor is shown immediately, and that the selection is reset via the mouse. To resolve the problem, change the code as shown below:

      C#
      private void gridView1_FocusedColumnChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedColumnChangedEventArgs e) { BaseView view = sender as BaseView; if (view == null) return; if (MouseButtons == System.Windows.Forms.MouseButtons.Left) return; view.ShowEditor(); TextEdit editor = view.ActiveEditor as TextEdit; if (editor != null) editor.SelectAll(); }

      Please try this solution, and let me know your results.
      Thanks,
      Stan.

      DS DS
      Daniel Schealler 14 years ago

        Spot on!
        Thanks Stan.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.