My datagridview is not filtering the columns.

kodandekod

New member
Joined
Apr 26, 2012
Messages
3
Programming Experience
Beginner
Hello

I have a datagridview.I fill my datagridview using csv file. I need to filter it using 2 datetimepickers. The filter must display only the columns which are the start date, range of columns between start date and end date, end date. I give you the code and the screenshots that how my program result must look like. My code is not working here even after click the button1 it not filters. Please can any check this. sorry for bad english.Here are my csv file,code and images. My result must look like the image 2. here the tportera column must not be filtered. it must remain there.



HTML:
Tportera,12/25/2010,12/26/2010,12/27/2010,12/28/2010,12/29/2010,12/30/2010,12/31/2010
1Flygplan,11Kr12Kr,13Kr14Kr,15Kr16Kr,17Kr18Kr,19Kr20Kr,21Kr22Kr,23Kr24Kr
2Flygplan,21Kr22Kr,23Kr24Kr,25Kr26Kr,27Kr28Kr,29Kr30Kr,31Kr32Kr,33Kr34Kr
3Flygplan,31Kr32Kr,33Kr34Kr,35Kr36Kr,37Kr38Kr,39Kr40Kr,41Kr42Kr,43Kr44Kr
4Flygplan,41Kr42Kr,43Kr44Kr,45Kr46Kr,47Kr48Kr,49Kr50Kr,51Kr52Kr,53Kr54Kr
5Flygplan,51Kr52Kr,53Kr54Kr,55Kr56Kr,57Kr58Kr,59Kr60Kr,61Kr62Kr,63Kr64Kr
3Flygplan,31Kr32Kr,33Kr34Kr,35Kr36Kr,37Kr38Kr,39Kr40Kr,41Kr42Kr,43Kr44Kr
2Flygplan,21Kr22Kr,23Kr24Kr,25Kr26Kr,27Kr28Kr,29Kr30Kr,31Kr32Kr,33Kr34Kr


VB.NET:
Imports System.IO
Public Class Form1
Dim dtFriends As New DataTable
Dim filename As String = ""
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
filename = "C:\Documents and Settings\AVILAJ\Desktop\Test Folder\dt\codes.txt"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim splits As String()
Using sr As StreamReader = New StreamReader(filename)
'read the first line for the table column headers
splits = sr.ReadLine.Split(","c)
For i As Integer = 0 To UBound(splits)
dtFriends.Columns.Add(splits(i))
Next
'read the rest of the lines to add rows to the table
Do While Not sr.EndOfStream
splits = sr.ReadLine.Split(","c)
dtFriends.Rows.Add(splits)
Loop
End Using
Catch ex As Exception
Finally
DataGridView1.DataSource = dtFriends.DefaultView
End Try
        DateTimePicker1.Format = DateTimePickerFormat.Custom
        DateTimePicker1.CustomFormat = "MM/dd/yyyy"
        DateTimePicker2.Format = DateTimePickerFormat.Custom
        DateTimePicker2.CustomFormat = "MM/dd/yyyy"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim startDate As Date = DateTimePicker1.Value
        Dim endDate As Date = DateTimePicker2.Value
        Dim Days As Integer = (endDate - startDate).Days
        Dim CurrentDate As Date
        For i As Integer = 1 To Days
            Try
                CurrentDate = startDate.AddDays(Days)
                DataGridView1.Columns.Remove(CurrentDate.ToString("MM/dd/yyyy"))
            Catch
            End Try
        Next
End Sub

Codes3.png
codes4.png
 
Do you mean this?

For i As Integer = 0 To DataGridView1.ColumnCount - 1
If DataGridView1.Item(i, 0).Value < MyDate Then
DataGridView1.Columns.Item(i).Visible = False
End If
Next

 
Back
Top