filter my datagrid with all the results between 2 dates in 2 datatimepickers.

Locked filter my datagrid with all the results between 2 dates in 2 datatimepickers.

  • Donnerstag, 19. April 2012 19:47
     
     

    kks need a quick reply looking for code that will filter my datagrid with all the results between 2 dates in 2 datatimepickers. My table is not bound to the database. I'm looking for code that will work when the search button is pressed. can anyone help.? ill add an image of my form.

Alle Antworten

  • Donnerstag, 19. April 2012 19:48
     
     
  • Montag, 23. April 2012 03:14
    Moderator
     
     Beantwortet Enthält Code

    Hi Avidolly,

    Welcome to the MSDN forum.

    Datagrid is a Web UI control which doesn’t belong to VB.Net. So I assume you use datagridview.

    Instead of how to filter the date, your root issue is how to add a date column in datagridview. Here are some samples:

    DataGridView - Date column [Read Input format dd/MM/yyyy]: http://social.msdn.microsoft.com/Forums/en-US/vbide/thread/213eaacc-fb38-4c50-9f4f-197fa9cafad7

    How to add DateTimepicker control within a DataGridView column type: http://social.msdn.microsoft.com/Forums/en-US/vbide/thread/3ab0b15f-82dc-42ed-afc6-b5c47621e630/

    After you add the date column in datagridview, you can just using a loop to compare whether the date is between the two datetime. Here is a sample:

      Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            If DateTimePicker1.Value > DateTimePicker2.Value Then
                MessageBox.Show("hehe")
            End If
    End Sub

    Hope this helps.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us


  • Dienstag, 1. Mai 2012 05:48
    Moderator
     
     

    Hi Avidolly,

    We haven’t heard from you for several days. I’d like to mark my reply as answer firstly. If you have any additional questions, you also can unmark the replay and post your question here. 

    Sorry for any inconvenience and have a nice day.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us