SfDataGrid GridDateTimeColumn : disable the calendar picker feature
Hello,
I have a large SfDataGrid containing editable cells. In order to save space (a lot of columns), I would like to hide the calendar part of the GridDateTimeColumn cell. Also We don't need it during the editing of the value.
Is it possible ? If yes, how ?
Thanks for your help
Here is a screenshot of what I need to get rid of and a template code that you can update as you wish :
Attachment: SfGridDateTimeEdit_2e5d35dc.rar
Hi Nicolas Wagener,
Your requirement will be achieved by overriding the OnEditElementLoaded event in the GridCellDateTimeRenderer class. We prepared sample for your requirement.
Please refer the below code snippet:
|
public MainWindow() { InitializeComponent(); this.dataGrid.CellRenderers.Remove("DateTime");
this.dataGrid.CellRenderers.Add("DateTime", new GridCellDateTimeRenderer()); } }
public class GridCellDateTimeRenderer : GridVirtualizingCellRenderer<TextBlock, DateTimeEdit> { public GridCellDateTimeRenderer() { }
protected override void OnEditElementLoaded(object sender, RoutedEventArgs e) { (e.Source as DateTimeEdit).IsButtonPopUpEnabled = false; base.OnEditElementLoaded(sender, e); } } |
We hope this helps. Please let us know, if need any further assistance.
Regards,
Chidanand M.
Attachment: SfDataGrid_Demo_d1338555.zip
Hello Chidanand,
thank you for your help, but it did not work.
See the animated screenshot : when I enter edit mode and typing the new date > it doesn't change when I leave the cell.
For the Time : same think and it show me the date when I enter edit mode.
Can you try to update the project in .net 7 version ? (not in .net framework 4.7.2 like you did before ? )
Thank you.
Nicolas
Attachment: SfGridDateTimeEdit_55883dc0.rar
Hi Nicolas,
We regret for the inconvenience.
Your requirement can be achieved by overriding GridCellDateTimeRenderer instead of overriding the GridVirtualizingCellRenderer. We also modified the provided sample.
Find the sample in the attachment.
Kindly refer the below code snippet:
|
private void MainWindow_Loaded(object sender, RoutedEventArgs e) { this.DataContext = new DataViewModel();
this.grid.CellRenderers.Remove("DateTime"); this.grid.CellRenderers.Add("DateTime", new GridCellDateTimeRendererExt()); } }
public class GridCellDateTimeRendererExt : GridCellDateTimeRenderer { public GridCellDateTimeRendererExt() { }
protected override void OnEditElementLoaded(object sender, RoutedEventArgs e) { (e.Source as DateTimeEdit).IsButtonPopUpEnabled = false; base.OnEditElementLoaded(sender, e); } } |
We hope this helps. Please let us know, if need any further assistance.
Regards,
Chidanand M.
Attachment: SfGridDateTimeEdit_f734593d.zip
- 3 Replies
- 2 Participants
- Marked answer
-
NW Nicolas Wagener
- Aug 10, 2023 07:37 AM UTC
- Aug 17, 2023 01:08 PM UTC