Query |
Solution | |
How to make the cell can multi line edit. (E.g. Alt-Enter / Shift Enter will line return). (The default action of return key will auto add row). |
You can achieve this by creating a custom renderer for the text column and enable the Multiline for the UI element as given in the following code example.
Code example :
| |
how to allow user to adjust row height (just like use mouse to adjust) ? |
You can change the row height for the default rows and the header rows as given in the following code example.
Code example :
Please let us know whether your requirement is to change the row height by resizing the rows using mouse.
| |
How to focus on the first column on after row added. |
This can be achieved by moving the current cell to the desired cell on the DataGrid.View.Records.CollectionChanged event as shown in the following code example.
Code example :
|
public class CustomTextBoxCellRenderer : GridTextBoxCellRenderer
{
SfDataGrid DataGrid;
public CustomTextBoxCellRenderer(SfDataGrid DataGrid)
{
this.DataGrid = DataGrid;
}
protected override void OnInitializeEditElement(DataColumnBase column, RowColumnIndex rowColumnIndex, TextBox uiElement)
{
base.OnInitializeEditElement(column, rowColumnIndex, uiElement);
if(column.GridColumn.MappingName == "ProductName")
{
uiElement.Multiline = true;
uiElement.ScrollBars = ScrollBars.Vertical;
}
}
protected override void OnKeyDown(DataColumnBase dataColumn, RowColumnIndex rowColumnIndex, KeyEventArgs e)
{
if (dataColumn.GridColumn.MappingName == "ProductName")
{
if (e.KeyCode == Keys.Enter && this.DataGrid.CurrentCell.IsEditing)
return;
}
base.OnKeyDown(dataColumn, rowColumnIndex, e);
}
} |