We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Toggle cell editing (readonly) based on user keystroke...

I want (okay, the *user* wants) to make cells un-editable until they first hit return in that cell. So, I have an unbound, readonly grid. I''m using the CurrentCellKeyDown event to test for the enter key, and change the cell''s readonly attribute using this code: Dim gsi As New GridStyleInfo() gsi.ReadOnly = False Me.GridControl1.IgnoreReadOnly = True Me.GridControl1.SetCellInfo( _ Me.GridControl1.CurrentCell.RowIndex, _ Me.GridControl1.CurrentCell.ColIndex, _ gsi, _ Syncfusion.Styles.StyleModifyType.Changes) However, this code doesn''t work if I set the grid''s ActivateCurrentCellBehavior to GridCellActivateAction.SelectAll (presumably because the edit control -- a textbox -- is getting the keystrokes instead of the current cell. So my questions are: 1) Is there a way to process keystroke events from within the textbox editing control? 2) If I set the grid to GridCellActivateAction.None, how can I select all the existing text in the cell after I''ve change the readonly attribute? I tried the following code that I dredged from a forum message, but I don''t really understand it, and it doesn''t work anyway: CType(Me.GridControl1.CurrentCell.Renderer.Control, GridTextBoxControl).SelectAll() 3) Is there an altogether better technique for providing the same user-experience that you would suggest? Thanks, s.s.

2 Replies

AD Administrator Syncfusion Team July 28, 2004 05:24 AM UTC

Here is one way I think you can get the Enter key to toggle readonly and select all the text when the cell is toggled to not readonly. Set the ActivateCurrentCellBehavior to none. Handl grid.KeyDown and there toggle the readonly and select the text. Also handle CurrentCellMoved to set the ReadOnly back to true after the cell has finished editing. Here is a little sample.


AD Administrator Syncfusion Team July 28, 2004 04:32 PM UTC

Clay - Thank-you very much! That was just the ticket. It was pretty close to what I already had, but I wasn''t using the CurrentCell.BeginEdit() before attempting to access the GridTextBoxControl. Anyways, thanks again, and big kudos to you and Syncfusion for providing this stellar support venue. s.s.

Loader.
Live Chat Icon For mobile
Up arrow icon