Skip to content

SyncfusionExamples/how-to-select-all-text-in-edit-mode-in-grid-date-time-column-in-data-grid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

How to select all text in edit mode in GridDateTimeColumn in DataGrid(SfDataGrid)?

About the sample

This example illustrates how to select all text in edit mode in GridDateTimeColumn in DataGrid(SfDataGrid)?

By default, SfDataGrid enters into edit mode in GridDateTimeColumn the entire text is not selected. You can achieve this by customizing the GridDateTimeCellRenderer.

this.sfDataGridSample.CellRenderers.Remove("DateTime"); 
this.sfDataGridSample.CellRenderers.Add("DateTime", new CustomDateTimeEdit(this.sfDataGridSample));

public class CustomDateTimeEdit : GridDateTimeCellRenderer
{
    public CustomDateTimeEdit(SfDataGrid dataGrid)
    {
       DataGrid = dataGrid;
    }

    /// <summary>
    /// Gets or sets to specify the datagrid.
    /// </summary>
    protected SfDataGrid DataGrid { get; set; }

    protected override void OnInitializeEditElement(DataColumnBase column, RowColumnIndex rowColumnIndex, SfDateTimeEdit uiElement)
    {
         base.OnInitializeEditElement(column, rowColumnIndex, uiElement);

         if (DataGrid.CurrentCell != null)
         {
             if (DataGrid.CurrentCell.CellRenderer != null)
             {
                 var editingTextBox = (uiElement as SfDateTimeEdit).GetType().GetProperty("EditingTextBox", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                 (editingTextBox.GetValue(uiElement) as RichTextBox).Focus();
                 (editingTextBox.GetValue(uiElement) as RichTextBox).SelectAll();
             }
         }
    }
}

Requirements to run the demo

Visual Studio 2015 and above versions

About

How to select all text in edit mode in GridDateTimeColumn in DataGrid(SfDataGrid)?

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages