Home Forums WinForms controls Xceed Grid for WinForms get selected text Reply To: get selected text

User (Old forums)
Member
Post count: 23064

The problem is that once you click outside the cell/grid, the selected text does not exist anymore, since the cell is not in edition anymore.

A workaround would be to keep a reference to the selected text before exiting the edition mode, and get the reference in the button.  Here is a basic example on how to implement this. You will need to increment on it to cover all cases (e.g cover all columns, with different type of editors)

private void Form1_Load( object sender, EventArgs e )

{

    gridControl1.Columns[

“Col1” ].CellEditorManager.ActivatingControl += new CellEditorEventHandler( CellEditorManager_ActivatingControl );

    gridControl1.Columns[

“Col1” ].CellEditorManager.DeactivatingControl += new CellEditorEventHandler( CellEditorManager_DeactivatingControl );

}

void CellEditorManager_ActivatingControl( object sender, CellEditorEventArgs e )

{

    ( (

WinTextBox )e.Control ).TextBoxArea.KeyUp += new KeyEventHandler( TextBoxArea_KeyUp );

    ( (

WinTextBox )e.Control ).TextBoxArea.MouseUp += new MouseEventHandler( TextBoxArea_MouseUp );

}

void CellEditorManager_DeactivatingControl( object sender, CellEditorEventArgs e )

{

    ( (

WinTextBox )e.Control ).TextBoxArea.KeyUp -= new KeyEventHandler( TextBoxArea_KeyUp );

    ( (

WinTextBox )e.Control ).TextBoxArea.MouseUp -= new MouseEventHandler( TextBoxArea_MouseUp );

}

void TextBoxArea_KeyUp( object sender, KeyEventArgs e )

{

    selectedText = ( (

TextBoxArea )sender ).SelectedText.ToString();

}

void TextBoxArea_MouseUp( object sender, MouseEventArgs e )

{

    selectedText = ( ( TextBoxArea )sender ).SelectedText.ToString();

}

private void button1_Click( object sender, EventArgs e )

{

    System.Diagnostics.

Debug.WriteLine( selectedText );

}

Imported from legacy forums. Posted by André (had 3255 views)