Gridcontrol cell time

Hello,

I need to have a column cells to manually insert time.
I've tried the code below but can't block context menu and can't show some type dropdown clock.

gridControl1[1, 1].CellType = "DateTimePicker";
gridControl1[1, 1].CellValueType = typeof(DateTime);
gridControl1[1, 1].CellValue = DateTime.Now;
gridControl1[1, 1].Format = "HH:mm";

I've tried also:
gridControl1[1, 3].CellType = "MaskEdit";
gridControl1[1, 3].CellValueType = typeof(DateTime);
gridControl1[1, 3].Format = "HH:MM";
gridControl1[1, 3].MaskEdit.Mask = "99:99";

In this I can't disable context menu and always show 10:12 after I put some other time.

What is the best way to insert manually time? Without context menu? With dropdown clock?

Thanks


7 Replies

MS Malini Selvarasu Syncfusion Team December 11, 2024 02:01 PM UTC

Hi Dinis Ferreira,

Based on the information provided, we understand that you need to define the cell type as `DateTimePicker` with the dropdown clock. However, the `GridControl` doesn't directly support the `DateTimePicker` cell type. You will need to register custom cell types for the `GridControl`. We have relevant user guide documentation available. Please refer to the link below and let us know if it meets your requirements:
Additionally, we are unclear about your statement regarding "without context menu." Could you please provide more details on this? This will help us better understand your requirements and offer a prompt solution.
Thank you for your understanding and cooperation.
Regards,
Malini Selvarasu



DF Dinis Ferreira December 16, 2024 03:37 PM UTC

Hi Malini

In the attached image is an context menu and a dropdown example.

How can I disable the context menu?
Is it possible to show some kind of clock in the dropdown option instead of a calendar?


Thanks


Attachment: Grid_88a4340b.rar


MS Malini Selvarasu Syncfusion Team December 17, 2024 02:40 PM UTC

Hi Dinis Ferreira,
 

Query

Update

How can I disable the context menu?

Based on the information provided, we understand that you would like to disable the context menu for the `DateTimePicker`. This can be achieved by defining a custom cell renderer for the `DateTimeCell` and creating a custom cell model. Within this setup, you can disable the context menu for the `DateTimePicker` cell.

 

To assist you further, we have prepared a sample demonstrating this approach.Please review the sample and the accompanying code snippet, and let us know if it meets your requirements.

 

Code Snippet:

gridControl1.CellModels.Add("CustomDateTimePicker", new CustomDateTimePickerModel(gridControl1.Model));

public class CustomDateTimePickerModel : GridDropDownCellModel

{

     public CustomDateTimePickerModel(GridModel grid) : base(grid) { }

 

     public override GridCellRendererBase CreateRenderer(GridControlBase control)

     {

         return new CustomClockCellRenderer(control, this);

     }

}

 

public class CustomClockCellRenderer : DateTimeCellRenderer

{

     private DateTimePickerAdv DateTimePickerAdv;

     public CustomClockCellRenderer(GridControlBase grid, GridCellModelBase cellModel)

         : base(grid, cellModel)

     {

         FieldInfo fieldInfo = typeof(DateTimeCellRenderer).GetField("dateTimePicker", BindingFlags.NonPublic | BindingFlags.Instance);

         DateTimePickerAdv = (DateTimePickerAdv)fieldInfo.GetValue(this);

         this.DateTimePickerAdv.ContextMenu = new ContextMenu(new MenuItem[] { });

     }

}

 

If we have misunderstood your request or if your requirements differ, please provide additional details. This will help us better understand the issue and offer a more suitable solution.

 

Thank you for your cooperation and understanding.

Is it possible to show some kind of clock in the dropdown option instead of a calendar?

We are currently analyzing the scenario you reported and require additional time to validate it. We will provide an update on or before December 19, 2024.

 

We appreciate your patience in the meantime.


Regards,
Malini Selvarasu


Attachment: GridControl_Demo_c5655a99.zip


DF Dinis Ferreira December 18, 2024 09:02 AM UTC

Hi Malini

First part works fine, thanks.



MS Malini Selvarasu Syncfusion Team December 19, 2024 10:46 AM UTC

Hi Dinis Ferreira,

Based on the information provided, we understand that you wish to replace the DropDown Calendar with a DropDown Clock. The `DateTimePickerAdv` control has been used in the cell; however, this functionality is not supported in the `DateTimePickerAdv` control, so we cannot add a DropDown Clock.
Alternatively, you can display an up-down button in the `DateTimePickerAdv` control by setting the `ShowUpDown` property to `true`. This will allow you to adjust the time value using the up and down buttons. Please refer to the code snippet below for implementation.
 Code Snippet:
gridControl1.CellModels.Add("CustomDateTimePicker", new CustomDateTimePickerModel(gridControl1.Model));
public class CustomDateTimePickerModel : GridDropDownCellModel
{
     public CustomDateTimePickerModel(GridModel grid) : base(grid) { }
 
     public override GridCellRendererBase CreateRenderer(GridControlBase control)
     {
         return new CustomClockCellRenderer(control, this);
     }
}
 
public class CustomClockCellRenderer : DateTimeCellRenderer
{
     private DateTimePickerAdv DateTimePickerAdv;
     public CustomClockCellRenderer(GridControlBase grid, GridCellModelBase cellModel)
         : base(grid, cellModel)
     {
         FieldInfo fieldInfo = typeof(DateTimeCellRenderer).GetField("dateTimePicker", BindingFlags.NonPublic | BindingFlags.Instance);
         DateTimePickerAdv = (DateTimePickerAdv)fieldInfo.GetValue(this);
         this.DateTimePickerAdv.ContextMenu = new ContextMenu(new MenuItem[] { });
         this.DateTimePickerAdv.Format = DateTimePickerFormat.Time;
         this.DateTimePickerAdv.ShowUpDown = true;
 
     }
}

Thank you for your understanding.
Regards,
Malini Selvarasu


DF Dinis Ferreira December 23, 2024 10:09 AM UTC

Hi Malini,


This also works, thank you.




MS Malini Selvarasu Syncfusion Team December 24, 2024 09:14 AM UTC

Hi Dinis Ferreira,

We are glad to hear that your requirement has been fulfilled. Hence, we are closing this forum. Please feel free to reach out to us if you need further assistance. We are always happy to help.
Regards,
Malini Selvarasu


Loader.
Up arrow icon