This is a migrated thread and some comments may be shown as answers.

RadListView Modify Edited Value

2 Answers 259 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Brandon
Top achievements
Rank 1
Brandon asked on 22 Jan 2019, 09:11 PM

I have a column with which get's edited using the ListViewDateTimeEditor.

The question is, how do I format the value that gets submitted to the ListView.

To be clear, I have already formatted the ListViewDateTimeEditor to use the following: 

Dim Editor As New ListViewDateTimeEditor
TryCast(Editor.EditorElement, BaseDateTimeEditorElement).Format = DateTimePickerFormat.Custom
TryCast(Editor.EditorElement, BaseDateTimeEditorElement).CustomFormat = "MM/dd/yyyy"
e.Editor = Editor

 

Even with this formatting, it still submits the full DateTime to the ListView when finished editing.  How do I make it output only the formatted Date value, without the Time?

2 Answers, 1 is accepted

Sort by
0
Brandon
Top achievements
Rank 1
answered on 22 Jan 2019, 09:25 PM

Not sure if it's the proper way, but I figured out at least one way to do it.

I captured and processed it in the ListView's ItemEdited event.

Private Sub lvEquip_ItemEdited(sender As Object, e As ListViewItemEditedEventArgs) Handles lvEquip.ItemEdited
    If e.VisualItem.Data.ListView.CurrentColumn.Name = "Col23" Then
        Dim DT As DateTime
        DateTime.TryParse(e.VisualItem.Data("Col23"), DT)
        e.VisualItem.Data("Col23") = DT.ToShortDateString
    End If
End Sub
0
Dimitar
Telerik team
answered on 23 Jan 2019, 11:53 AM
Hi Brandon,

Your appraoch is ok if you are storing the data as a string. If you are storing a DateTime object you can use the CellFormatting event and change the text of the cell which would not affect the actual value:
Private Sub RadListView1_CellFormatting(ByVal sender As Object, ByVal e As ListViewCellFormattingEventArgs)
    Dim cell As DetailListViewDataCellElement = TryCast(e.CellElement, DetailListViewDataCellElement)
    If cell IsNot Nothing AndAlso cell.Data.Name = "Date" Then
        Dim value As Date = CDate(cell.Row("Date"))
 
        cell.Text = value.ToShortDateString()
    End If
End Sub

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ListView
Asked by
Brandon
Top achievements
Rank 1
Answers by
Brandon
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or