The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
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?
HAhaneefm Syncfusion Team 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();
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
HAhaneefm Syncfusion Team 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; } }