Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
UltraGrid
posted

Hi,

In ultragrid,the greater than filter is working for the numeric number but not working for date field[Datatype is datetime].I have checked the code from google,every thing is correct like MeetsCriteria override,BeforeRowFilterChanged  events etc. but not working.Help is required.

Thanks,

Dinakar

  • 100
    posted

    try setting the SortComparer, sort comparer class at the end...

     mainColumn = Me.UltraListView1.MainColumn
                                mainColumn.Key = dr("FIELD").ToString()
                                mainColumn.Text = dr("LABEL").ToString()
                                If Me._RepDocResultsPresenter.IsDateTimeDocumentField(dr("FIELD").ToString()) Then
                                    mainColumn.DataType = GetType(DateTime)
                                    mainColumn.SortComparer = New MainDateItemComparer()
                                Else
                                    mainColumn.DataType = GetType(String)
                                End If
                                If mainColumn.DataType.FullName = "System.DateTime" Then
                                    mainColumn.Format = "yyyy-MM-dd hh:mm:ss tt"
                                End If
     Class MainDateItemComparer
            Implements IComparer
            Private col As Integer
            Private order As SortOrder
            Public Sub New()
                col = 0
                order = SortOrder.Ascending
            End Sub
            Public Sub New(column As Integer, order As SortOrder)
                col = column
                Me.order = order
            End Sub
            Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
                Dim returnVal As Integer
                Debug.WriteLine(String.Concat(x.ToString, " ", y.ToString))
                ' Determine whether the type being compared is a date type.
                Try
                    ' Parse the two objects passed as a parameter as a DateTime.
                    Dim firstDate As System.DateTime = DateTime.Parse(CType(x,  _
                                            UltraListViewItem).Text)
                    Dim secondDate As System.DateTime = DateTime.Parse(CType(y,  _
                                              UltraListViewItem).Text)
                    ' Compare the two dates.
                    returnVal = DateTime.Compare(firstDate, secondDate)
                    ' If neither compared object has a valid date format,
                    ' compare as a string.
                Catch
                    ' Compare the two items as a string.
                    returnVal = [String].Compare(CType(x,  _
                                      UltraListViewItem).Text, CType(y, UltraListViewItem).Text)
                End Try
                ' Determine whether the sort order is descending.
                If order = SortOrder.Descending Then
                    ' Invert the value returned by String.Compare.
                    returnVal *= -1
                End If
                Return returnVal
            End Function
        End Class