How can I get the selected text in an active gridcell

Platform: WinForms| Category: Datagrid

You need to get the DataGridTextBoxColumn.TextBox member, and retrieve the SelectedText from it for the active cell. The sample shows how you can do this as part of handling this TextBox’s rightClick. This code assumes you have specifically added DataGridTextBoxColumn for each column style. You can also download a VB sample.

private void HandleMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
  if(e.Button == MouseButtons.Right)
  {
    DataGridTableStyle ts = dataGrid1.TableStyles[''customers''];
    DataGridTextBoxColumn cs = (DataGridTextBoxColumn)ts.GridColumnStyles[dataGrid1.CurrentCell.ColumnNumber];
    MessageBox.Show(''Selected: '' + cs.TextBox.SelectedText);

  }
}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.