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

Excel Cell Click Behaviour.


Hi,
 i am facing issue wrt to Excel Click.

Problem  : Double Click on cell then cursor should point to to the letter where I am clicked. This is exactly same behavior in Excel Cell text Selection.

I am using the below code,

this.grid.Model.Options.ActivateCurrentCellBehavior = GridCellActivateAction.DblClickOnCell | GridCellActivateAction.PositionCaret;

with above code change, cell gets actvated on double click but cursor will be pointed to end of the content on right side.

But I need , Double Click on the Cell and Cursor should point to the exact position where I am clicked. Exact feature like excel cell text selection



1 Reply

JS Jayapradha S Syncfusion Team April 8, 2015 02:48 AM UTC

Hi Basavaraj,

Thank you for using Syncfusion products.

We have analyzed your requirement and you can placed the cursor position where you clicked like in Excel by using PreviewMouseLeftButtonDown and CurrentCellStartEditing Event as shown in the below code snippet,


Code Snippet:

void grid_CurrentCellStartEditing(object sender, Syncfusion.Windows.ComponentModel.SyncfusionCancelRoutedEventArgs args)

{

if (doubleClickArgs != null)

{

this.Dispatcher.BeginInvoke(new Action(SetCursorPosition),System.Windows.Threading.DispatcherPriority.ApplicationIdle);

}

}


void grid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)

{

if(e.ClickCount==1)

doubleClickArgs=e;

else

doubleClickArgs=null;

}

private MouseButtonEventArgs doubleClickArgs = null;


private void SetCursorPosition()

{

GridCurrentCell cc = this.grid.Model.CurrencyManager.CurrentCell;

if (cc.Renderer.CurrentCellUIElement is TextBox)

{

TextBox tb = cc.Renderer.CurrentCellUIElement as TextBox;

if (doubleClickArgs != null)

{

Point pt = doubleClickArgs.GetPosition(tb);

tb.SelectionStart = tb.GetCharacterIndexFromPoint(pt, true) + 1;

tb.SelectionLength = 0;

}

doubleClickArgs = null;

}
}


We have prepared a sample to achieve your requirement and please find the sample from the below location,

Sample Link: GridDataControlsample.zip

Kindly let us know if this solution helps you.

Regards,
Jayapradha

Loader.
Live Chat Icon For mobile
Up arrow icon