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.
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.
Hi Daniel,
Thank you for your question. The cause of this behavior is that the grid stores the previous cell state before switching the focus and restores it after another cell is focused. So, if the previous cell was not editable, the editor was inactive and the next cell will not automatically show the editor when the focus is changed. Basically, your solution is quite correct. However, to prevent the selection from being broken, you can set the OptionsBehavior.EditorShowMode property to MouseUp. I have attached a sample project, which demonstrates how to implement this feature. Please review it and inform me whether this approach suits your needs.
Thanks,
Stan.
Hey Stan
The Sample demonstrates exactly the behaviour I'm looking for.
I'm currently checking up on my current solution to try and find what I missed. My KeyUp is already set, so I must be doing something else to cause my behaviour to diverge from the sample.
Thanks for your time.
I've managed to duplicate my behaviour in the sample. As per usual, the difference was obvious once I'd worked it out.
I'm using spineditors on my grid.
To replicate my issue, follow these steps:
Alternatively:
However, this can be 'fixed' if we go into the source code and comment-out line 28: //view.ShowEditor();
Now, both the tests above will lead to the text in step 2 auto-selecting as desired. However, we will have lost the ability to scroll through the grid using the Tab key.
Is there something special I should be doing in the SpinEdit control? None of the properties in the repository viewer are appealing to intuition.
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:
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.
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:
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.
Spot on!
Thanks Stan.