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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to clobber the CurrentCell''s controltext when handling key-events

Thread ID:





34046 Aug 31,2005 07:07 PM UTC Sep 2,2005 03:42 PM UTC WinForms 8
Tags: GridControl
Ken Overton
Asked On August 31, 2005 07:07 PM UTC

I want to have special keys that behave like macros or keying shortcuts that change the controltext of the current cell. For example, I''m handling CurrentCellKeyDown, and when I receive a "[" or "]" I need to rewrite the contents of the cell based on a certain calculation. I do that succesfully by setting CurrentCell.Renderer.ControlText and setting the event.Handled = true, but in the UI I end up in edit-mode with my editing text set as "]". If I ESC at that point it reverts to the value I wrote into CurrentCell.Renderer.ControlText, but how do I totally get rid of anything that thinks the current editing state is "]" (or "[")?

Administrator [Syncfusion]
Replied On August 31, 2005 07:12 PM UTC

You can try casting grid.CurrentCell.Renderer to a GridTextBoxCellRenderer, call it cr. Then you can try setting cr.TextBox.Text to be the string you want to see in the editing cell.

Ken Overton
Replied On August 31, 2005 07:43 PM UTC

When I try that I briefly see the new value that I''m writing, then the state drops into editing mode with contents "]". The final behavior I''m aiming for, btw, is to keep the cell activated and editing and allow the user to enter "]" or "[" as many times as they want, seeing the values change as I compute them. Then when they see a value they want, then they hit "return" and I do something different.

Administrator [Syncfusion]
Replied On August 31, 2005 10:03 PM UTC

Here is a little sample using CurrentCellValidateString. http://www.syncfusion.com/Support/user/uploads/GC_77fdff7d.zip If you type a open bracket, [, it will auatomatically add ''abcd'' after the bracket.

Ken Overton
Replied On September 1, 2005 03:00 PM UTC

Very cool! ..... but .... unfortunately doesn''t work if you use arrow keys to reach a cell. I.e., if you''re not in edit mode, it doesn''t work. But I could use this if I could just find a way to force people into that mode when I want to (like when they''ve arrowed to a cell and started typing "["''s in it). Any way I can do that. Unfortunately our users use the mouse about once an hour and do most navigation thru the keyboard.

Administrator [Syncfusion]
Replied On September 1, 2005 04:05 PM UTC

Try setting the grid.ActivateCurrentCellBehavior property to SetCurrent.

Ken Overton
Replied On September 1, 2005 07:42 PM UTC

>Try setting the grid.ActivateCurrentCellBehavior property to SetCurrent. Thanks again, for the suggestion. I don''t think that''s gonna be acceptable to the traders, as they can''t arrow right and left seamlessly from column to columnt with this setting; they end up arrowing through each and every character in each column.

Administrator [Syncfusion]
Replied On September 1, 2005 08:59 PM UTC

Try this. It worked for me without using teh SetCurrent setting.
private void gridControl1_CurrentCellValidateString(object sender, GridCurrentCellValidateStringEventArgs e)
		GridCurrentCell cc = this.gridControl1.CurrentCell;

		GridTextBoxCellRenderer cr = cc.Renderer as GridTextBoxCellRenderer;
		cr.TextBox.Text = e.Text + "abcde";
		cr.TextBox.SelectionLength = 0;
		cr.TextBox.SelectionStart = cr.TextBox.Text.Length;
		e.Cancel = true;

Ken Overton
Replied On September 2, 2005 03:42 PM UTC

Yes! That does what I want, thanks a lot.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon