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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Select text programmatically in GridTextBoxCellRenderer

Thread ID:

Created:

Updated:

Platform:

Replies:

67771 Aug 29,2007 07:15 PM UTC Sep 7,2007 12:32 AM UTC WinForms 3
loading
Tags: GridControl
Yuval
Asked On August 29, 2007 07:15 PM UTC

Hi,
I am programming with c# visual studio 2005 and syncfusion 4.4

I want to select text programmatically in GridTextBoxCellRenderer (in GridDataBoundGrid)
I tried to play with GridTextBoxCellRenderer.TextBox.Select()/SelectAll() methods but i didn't succeed
How i can do this?

Thanks,
Yuval

haneefm [Syncfusion]
Replied On August 30, 2007 12:25 AM UTC

Hi Yuval,

Here is a code snippet that will highlight the text in a cell. It makes sure the proper cell is active and being edited as this is the only way you can display selected text in a cell currently. Now if you want to simultaneously select text in several cells, that would require a custom cell control with you drawing the selection rectangle yourself within the cell. This code uses the standard selection process of the edit control which is only available for the currentcell.

public void SelectCellText(int row, int col)
{
this.GridControl1.Focus();
if ( ! this.GridControl1.CurrentCell.HasCurrentCellAt(row, col) )
this.GridControl1.CurrentCell.MoveTo(row, col, Syncfusion.Windows.Forms.Grid.GridSetCurrentCellOptions.SetFocus | Syncfusion.Windows.Forms.Grid.GridSetCurrentCellOptions.ScrollInView, false);
else if ( ! this.GridControl1.CurrentCell.IsEditing )
this.GridControl1.CurrentCell.BeginEdit();

GridTextBoxControl tb = this.GridControl1.CurrentCell.Renderer.Control as GridTextBoxControl;
tb.SelectionLength = selLength;
tb.SelectionStart = selStart;
}

Best regards,
Haneef

Yuval
Replied On August 30, 2007 06:15 PM UTC

Thank you you on the answer!
Is worked,
But now there is a different problem that not hanging in the previous problem,
when I enter the cell that his text is long from width of the cell, and I move with the cursor to the text that not saw him at the time the entrance to the cell, the new text is exposed is selected(marked) how I cause so that this text will not be selected?

Thanks,
Yuval

haneefm [Syncfusion]
Replied On September 7, 2007 12:32 AM UTC

Hi Yuval,

One way you can do this by handling the CurrentCellKeyDown event of the grid and set e.Handled to true for invisible cell selected text in a gridcell. Here are the codes the show this task.

private void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
GridControl _grid = sender as GridControl;
GridCurrentCell cc = _grid.CurrentCell;
if (cc.IsEditing && e.KeyCode == Keys.Right )
{
GridTextBoxCellRenderer cr = _grid.CurrentCell.Renderer as GridTextBoxCellRenderer;
TextBoxBase tb = cr.TextBox;
if (tb != null && tb.SelectionLength > 0)
{
int length = tb.SelectionStart > tb.SelectionLength ?tb.SelectionStart: tb.SelectionLength + tb.SelectionStart ;
string s = tb.Text.Substring(0, length);
int width = (int)tb.CreateGraphics().MeasureString(s, tb.Font).Width;
if (width >= _grid.ColWidths[cc.ColIndex])
{
e.Handled = true;
}
}

}
}

Best regards,
Haneef

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;