Determine and replacing selected text in a text cell

I need to implement the following:

1) Handle right-click on a text grid cell
2) Determine where on the text the click was
3) Change the selection to the word which was clicked (for my definition of word)
4) Get the string representing the word
5) DoSomething(Word)
6) Replace the original word with the result of (5) above

Looking at the grid interface I could not do most of the above. Can you please tell me if this is possible?

1 Reply

HA haneefm Syncfusion Team October 5, 2007 06:13 PM UTC

Hi Kamen,

This can be achived by handling the CurrentCellControlGotFocus event of the Grid and subscribe the GridTextBoxControl.MouseDown event to detect the right mousebutton. In the MouseDown eventhandler, you can use the TextBox.SelectionLength/TextBox.SelectedText property of the GridTextBoxControl to replace the selected text. Below are the codes:

private void gridControl1_CurrentCellControlGotFocus(object sender, System.Windows.Forms.ControlEventArgs e)
{
GridTextBoxControl GridTextBox = e.Control as GridTextBoxControl;
GridTextBox.MouseDown +=new MouseEventHandler(GridTextBox_MouseDown);
}
private void GridTextBox_MouseDown(object sender, MouseEventArgs e)
{
if( e.Button == MouseButtons.Right )
{
GridTextBoxControl GridTextBox = sender as GridTextBoxControl;
if( GridTextBox.SelectionLength > 0)
{
GridTextBox.SelectedText = "RightProcess";
}
}
}

Please refer to the attached sample for implementation and let me know if this helps.
ReplaceSelectText.zip

Best regards,
Haneef

Loader.
Up arrow icon