Home › Forums › WinForms controls › Xceed Grid for WinForms › get selected text
-
AuthorPosts
-
#16800 |
Hi,
How do I get the selected text from the current cell?
So, say the user presses a button (outside of grid) a message pops up with the current cells selected text.
vb.net pleaseThanks in advance.
Imported from legacy forums. Posted by troy@querytool.com (had 2944 views)
well you can do that using DataGridControl class. the following code snippet shows current selected item text in message box. its in C# but i hope you will be able convert it to VB.
private void DGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
DataGridControl dataGridControl = sender as DataGridControl;
if (dataGridControl != null)
{
Xceed.Wpf.DataGrid.Row row = (Xceed.Wpf.DataGrid.Row)dataGridControl.GetContainerFromItem(dataGridControl.CurrentItem);
Xceed.Wpf.DataGrid.Cell currentCell = row.Cells[dataGridControl.CurrentColumn.Index];
if (currentCell != null && currentCell.HasContent)
{
MessageBox.Show(currentCell.Content.ToString());
}
}
}regards
dEXtER2k
Imported from legacy forums. Posted by dEXtER.2k (had 353 views)
The previous answer is for the WPF DataGrid, but this thread is for the .NET Grid.
You can get the CurrentCell Value and display it.
e.g.:
gridControl1.CurrentCell.Value.ToString()
Imported from legacy forums. Posted by André (had 277 views)
But I only want the selected text of the currentcell. So if the cell value is abcd, and the user has selected cd, then that’s what I want to return.
Regards.Imported from legacy forums. Posted by troy@querytool.com (had 633 views)
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)
-
AuthorPosts
- You must be logged in to reply to this topic.