C1TrueDBGrid -- how to clear date cells

Posted by: adam.dawes on 14 June 2019, 4:14 am EST

    • Post Options:
    • Link

    Posted 14 June 2019, 4:14 am EST

    I have numerous C1TrueDBGrids in an application, many of which contain date columns. These mostly work very well and display the pop-up calendar when put into edit mode.

    However I’ve realised that once a date has been entered, there doesn’t appear to be any way to remove the date and revert back to a blank (null) cell value. Obviously this can be achieved through code, but I want the user to be able to do this through the UI.

    Is there a way to do this?

    Thanks!

  • Posted 14 June 2019, 7:30 am EST

    Hello,

    Please use the following line of code to achieve your requirement:

    
      C1.Win.Calendar.C1DateEdit dt = new C1.Win.Calendar.C1DateEdit();
                this.Controls.Add(dt);
                dt.EmptyAsNull = true;
                c1TrueDBGrid1.Columns[3].EnableDateTimeEditor = false;
                c1TrueDBGrid1.Columns[3].Editor = dt;
    
    

    Thanks.

  • Posted 14 June 2019, 10:36 am EST

    Hi mohitg,

    Thanks very much for that suggestion, I’ve been able to create a workable solution for the problem using this approach.

    Adam.

  • Posted 1 August 2019, 8:22 pm EST

    Hello,

    I have a similar problem with the C1FlexGrid and I am using a C1DateEdit as the Editor for my column style.

    I tried setting .EmptyAsNull = True but if the user clicks clear on the calendar or highlights and deletes the date, as soon as you leave the cell, the old date vale comes back.

    Thanks Brian

  • Posted 2 August 2019, 2:43 am EST

    Hello,

    Sorry, I can’t replicate the issue at my end. C1DateEdit as editor is working fine at my end and I am able to clear or delete the date in the cell without retrieving the old value.

    Please find the attached sample demonstrating the same.

    Please modify the attached sample accordingly to replicate the issue so that I can narrow down the problem.

    Thanks and Regards,

    Prabhat Sharma

    FlexGridDateEditEditorDemo.zip

  • Posted 2 August 2019, 3:39 am EST

    Mr Sharma,

    Thank you for your response. I am trying to load your example but I am getting an error that I don’t know how to correct.

    Severity Code Description Project File Line Suppression State

    Error Unable to resolve type ‘C1.Win.Calendar.C1DateEdit, C1.Win.Calendar.4’ FlexGridDateEditEditorDemo D:\Temp\FlexGridDateEditEditorDemo\Properties\licenses.licx 2

    I don’t know if the problem is that my version is 4.0.20151.38 ?

    Regards

    Brian Morris

  • Posted 2 August 2019, 8:46 am EST

    Hello,

    You are getting this error because I am using DateEdit control of C1Calendar class and this was introduced in 2017V1 and your version is 2015V1.

    You can use C1DateEdit of C1Input class as an editor of the column.

    I have updated the sample accordingly, please have a look.

    Thanks and Regards,

    Prabhat Sharma.

    DateEditFlexGrid.zip

  • Posted 2 August 2019, 9:34 am EST

    Thank you so much. I will try and let you know.

  • Posted 2 August 2019, 5:46 pm EST

    Mr Sharma,

    It seems that it works when you set the set the column with the editor

    .Cols(“TranDate”).Editor = Me.C1DateEditor

    but not if I use a style and had set the editor to the style like

    Dim cs As C1.Win.C1FlexGrid.CellStyle = Me.C1FlexGrid1.Styles.Add(“dates”)

    cs.Editor = Me.C1DateEditor

    .Cols(“TranDate”).Style = .Styles(“dates”)

    It seems that the problem is using the styles. Even if I don’t do cs.Editor = Me.C1DateEditor, once I set the style it does not work.

    Mr Sharma, is there a way so that once I tab into the cell I can press Delete key to clear instead of F2 then Delete ?

  • Posted 5 August 2019, 6:43 am EST

    Hello,

    1 : I can’t replicate the issue at my end by setting the Editor through Style property of the Column. I have used the same code as given by you in the last reply.

    2 : To clear the cell value directly by pressing the Delete key, you need to handle it manually through KeyDown event of FlexGrid.

    Code Snippet is given below :

    Private Sub C1FlexGrid1_KeyDown(sender As Object, e As KeyEventArgs) Handles C1FlexGrid1.KeyDown
        If e.KeyCode = Keys.Delete Then
           C1FlexGrid1.SetData(C1FlexGrid1.Row, C1FlexGrid1.Col, Nothing, True)
        End If
    End Sub
    

    Please refer to the sample where I have implemented both the above given points.

    Thanks and Regards,

    Prabhat Sharma.

    DateEditeditorDemoVB.zip

  • Posted 5 August 2019, 10:01 am EST

    Mr Sharma,

    1. It could be a bug in the version I have that got fixed in a newer version maybe? I will see if I can make a demo for you.

    2. Thanks I will try this.

  • Posted 6 August 2019, 1:50 am EST

    Hello,

    I have checked with the build mentioned by you i.e. 4.0.20151.38 in the earlier post and it is working fine at my end.

    If you need any other help, please let us know.

    Thanks and Regards,

    Prabhat Sharma.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels