in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Find closest match in dataview

Last post 04-03-2008 12:16 PM by C1_AndreyD. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 04-03-2008 11:12 AM

    Find closest match in dataview

     I have a dataview full of dates in order. I can search the dataview to find a certain date, but if that date is not there is there a way to find the next closest date by using an expression or by some other means?

     

    Thanks. 

     
     

  • 04-03-2008 12:16 PM In reply to

    Re: Find closest match in dataview

    Hi,

    Attached is a small sample that finds the closest match in a dataview.
    The following is the whole code of that sample.

    Imports C1.Data
    Imports C1.Data.SchemaObjects

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    Dim searchDate As DateTime = DateTimePicker1.Value.Date
    Dim index As Int32
    Dim field As DataField = C1DataView1.DataTable.Fields("OrderDate")
    For index = 0 To C1DataView1.Count - 1

    Dim test As Object = C1DataView1(index)(field)
    If TypeOf test Is DateTime AndAlso test >= searchDate Then

    C1DataView1.Position = index
    Exit Sub

    End If

    Next
    End Sub

    End Class

    Hope this will help.

    Regards,

    -Andrey
Page 1 of 1 (2 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.