Home Forums WinForms controls Xceed Grid for WinForms How to use datepicker in cellviewer

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17604 |

    Hi all,

    we’ve migrated from XCeed Grid 2.2 to 3.9..Now we have noticed a problem on editing a date-cell. The date cell should display e.g. ‘Jun 2011’. This works as desgined. But when a user wants to edit this value nothing happens: The calendar control does not open. I use the following settings on the grid column:

    FormatDateColumnHeader =

    New System.Globalization.DateTimeFormatInfo

    FormatDateColumnHeader.ShortDatePattern =

    “MMM yyyy”

    gridcol.FormatProvider = GridGeneral.FormatDateColumnHeader

    gridcol.FormatSpecifier =

    “d”

    This worked fine with XCeed Grid 2.2, but at least in my case it’S not working. What yould be the correct way of solving thigs?

    Thanks in advance!

    Imported from legacy forums. Posted by Kai (had 3054 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Kai, 

    Can you send us a sample application that reproduces this behavior so that we investigate this in more detail?

    You can send it to support@xceed.com. Please include a reference to this forum post in your email.

     

    Imported from legacy forums. Posted by Michel [Xceed] (had 375 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Michel,

     I’ve created an example project and sent it to your support email. Basically this is what I’m doing:

     


    Public Sub CreateTestGrid()


    Dim NewCol As New Xceed.Grid.Column(“Test”, GetType(Date))

    GridControl1.Columns.Add(NewCol)

    Dim FormatDateComponent As New System.Globalization.DateTimeFormatInfo


    FormatDateComponent.ShortDatePattern = “MMM yyyy”


    NewCol = New Xceed.Grid.Column(“Test2”, GetType(Date))


    NewCol.FormatSpecifier = “d”

    NewCol.FormatProvider = FormatDateComponent

    GridControl1.Columns.Add(NewCol)

    Dim Row As Xceed.Grid.DataRow

    Row = GridControl1.DataRows.AddNew()

    Row.Cells(0).Value = Now

    Row.Cells(1).Value = Now

    Row.EndEdit()

    End Sub

     

    When I click on Cell 1 the calendar opens, but when I click on Cell 2 nothing happens.

    http://imageshack.us/photo/my-images/860/snapshot001d.png/

     

    Thanks

    Kai

    Imported from legacy forums. Posted by Kai (had 346 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Kai,

    To achieve the behavior you want, you must treat the CellViewManager and the CellEditorManager differently. I have edited your code to fit your needs.

    ————————-

    Public Sub CreateTestGrid()
            Dim NewCol As New Xceed.Grid.Column(“Test”, GetType(Date))
            GridControl1.Columns.Add(NewCol)

            Dim FormatDateComponent As New System.Globalization.DateTimeFormatInfo
            FormatDateComponent.ShortDatePattern = “MMM yyyy”

            NewCol = New Xceed.Grid.Column(“Test2”, GetType(Date))
            Dim dtpEditor As New DateTimePicker
            dtpEditor.Format = DateTimePickerFormat.Custom
            dtpEditor.CustomFormat = “MMM yyyy”
            Dim dtpViewer As New DateTimePicker
            dtpViewer.Format = DateTimePickerFormat.Custom

            dtpViewer.CustomFormat = “MMM yyyy”

            Dim dateEditor As New DateEditor()

            NewCol.CellEditorManager = New CellEditorManager(dtpEditor, “Value”, True, True)

            NewCol.FormatSpecifier = “d”
            NewCol.FormatProvider = FormatDateComponent

            GridControl1.Columns.Add(NewCol)

            Dim Row As Xceed.Grid.DataRow
            Row = GridControl1.DataRows.AddNew()
            Row.Cells(0).Value = Now
            Row.Cells(1).Value = Now
            Row.EndEdit()
        End Sub

    ————————-

    Imported from legacy forums. Posted by Marc [Xceed] (had 396 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Marc,

    works fine so far, thanks! (Even though I think some lines could be removed, e.g. ‘dtpViewer’ is not used as far as I see)

     

    Nevertheless there is still a problem: If the cell does not contain any value, the calendar control is not displayed. Remove the next to last line ‘Row.Cells(1).Value = Now’ to test it. How could that be fixed?

    Thanks

    Kai

    Imported from legacy forums. Posted by Kai (had 358 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Kai,

    There is a workaround for this because by default, the CellEditor does not come up when the value of the DataCell is Nothing. You can intercept the click event on the cell and handling the event yourself. For example:

    ———-

    AddHandler Row.Cells(1).Click, AddressOf CellClicker

    ———-

    and your event handler would look like this:

    ———-

    Private Sub CellClicker(sender As Object, e As EventArgs)
            Console.WriteLine(sender.ToString())
            Dim cell As DataCell = CType(sender, DataCell)

            If (cell.Value = Nothing) Then
                cell.Value = Now
            End If
        End Sub

    ———-

     

    Your basically forcing the CellEditor to come up if the value is Nothing by assigning a default value such as Now to the cell. To the user, they will not see this and they will thing that by bringing the DatePicker they need to choose a date.

    Imported from legacy forums. Posted by Marc [Xceed] (had 366 views)

    User (Old forums)
    Member
    Post count: 23064

    HI Marc,

    thanks for your answer. Just one clarification before I implement it. You wrote ” by default, the CellEditor does not come up when the value of the DataCell is Nothing.” Is there any other way? To me it’s strange that I have to register on the click-event to fill the cell so that the datepicker pops up. At least with XCeed Grid 2.2 this was not the case, it worked fine also for empty cells. So before registering event (making it more complicate to maintain the application later on) I’d like to be sure that this is the easiest option.

    Thanks

    Kai

    Imported from legacy forums. Posted by Kai (had 412 views)

    Xceed Support
    Member
    Post count: 5658

    Hi ,

    A request has been sent to the development team in order to resolve this issue. We will consider this for a future service release,  but in the meantime, the workaround we provided would be the easiest way to go.

    I apologize for the inconvenience. 

    Imported from legacy forums. Posted by Michel [Xceed] (had 346 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Michel,

    ok, I’ve implemented your proposed solution and it works as expected. Thanks for your support and clarification!

    Kind regards

    Kai

    Imported from legacy forums. Posted by Kai (had 2407 views)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.