I Have Listview with All transaction

with column InvoiceNo Date Customer Total

Now I want to filter only month transation only month with combobox selection and one textbox year

Me.cboMonth.Items.Add("1")
Me.cboMonth.Items.Add("2")
Me.cboMonth.Items.Add("3")
...........
Me.cboDate.Items.Add("12")
Me.cboDate.SelectedText = 1

my column date display mm/dd/yyyy

How can I selection cboMonth to filter only month transaction

Please help...
Thanks

See if this helps.

Public Class Form1
    Private itms() As ListViewItem '// stores itms from ListView.

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        With ComboBox1.Items : For i As Integer = 1 To 12 : .Add(CStr(i)) : Next : End With '// load cmb(ComboBox).
        With ListView1.Items
            .Add(New ListViewItem("1,01/02/03".Split(",")))
            .Add(New ListViewItem("1,01/04/03".Split(",")))
            .Add(New ListViewItem("1,01/02/03".Split(",")))
            .Add(New ListViewItem("1,02/02/03".Split(",")))
            .Add(New ListViewItem("1,03/04/03".Split(",")))
            .Add(New ListViewItem("1,02/02/23".Split(",")))
        End With
        setCoolListViewItemsInArray(ListView1) '// IMPORTANT: after loading the ListView w/.Items, always set this.
    End Sub
    Private Sub setCoolListViewItemsInArray(ByVal selCoolListView As ListView)
        ReDim itms(selCoolListView.Items.Count - 1) '// reset the lenght of Array to lv.Items.Count
        For i As Integer = 0 To selCoolListView.Items.Count - 1
            itms(i) = selCoolListView.Items(i) '// set each array.itm as the appropriate lv.itm.
        Next
    End Sub

    Private Sub _ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        With ComboBox1
            If Not .Text = "" Then filterCoolListView(ListView1, .Text)
        End With
    End Sub
    Private Sub filterCoolListView(ByVal selCoolListView As ListView, ByVal selCoolMonth As String)
        selCoolListView.Items.Clear() '// clear for new input.
        For Each itm As ListViewItem In itms '// loop thru all itms in Array.
            With itm.SubItems(1).Text '// check Column2.Text
                If CInt(.Substring(0, .IndexOf("/"))) = CInt(selCoolMonth) Then '// get all text prior to the first "/".
                    selCoolListView.Items.Add(itm) '// if a match, add to ListView.
                End If
            End With
        Next
    End Sub
End Class

I tried using ListView.ListViewItemCollection , though it kept clearing the Collection every time I cleared the ListView; very odd.

If CInt(.Substring(0, .IndexOf("/"))) = CInt(selCoolMonth) Then '// get all text prior to the first "/".

error...
Conversion from string "1/" to type 'Integer' is not valid.

Ok.... now I can filter my Listview with month...
with add

setCoolListViewItemsInArray(ListView1) '// IMPORTANT: after loading the ListView w/.Items, always set this.

thank codeorder

good...

thank codeorder

My listview now can short with month after select combobox1
If I want auto select for month now
after open form listview I must select combobox1
I want auto for filter for month now..
please help...
tx

Add this to Form1_Load , just after you setCoolListViewItemsInArray(ListView1) .

ComboBox1.SelectedIndex = 1 '// select 2nd item in ComboBox.

This will trigger the _ComboBox1_SelectedIndexChanged and cause it to fire off the code within.

.btw, welcome to the forum AndAlso glad I could help.:)

Private Sub filterCoolListView(ByVal selCoolListView As ListView, ByVal selCoolMonth As String)
selCoolListView.Items.Clear() '// clear for new input.
For Each itm As ListViewItem In itms '// loop thru all itms in Array.
With itm.SubItems(1).Text '// check Column2.Text
If CInt(.Substring(0, .IndexOf("/"))) = CInt(selCoolMonth) Then '// get all text prior to the first "/".
selCoolListView.Items.Add(itm) '// if a match, add to ListView.
End If
End With
Next '-> NullReferenceExCeption was unhandle by user code
Object reference not set to an instance of an object.

There is no transaction today... after have transaction it is ok... no error

Use a Try/Catch for each itm and If you still get results, Then it is just that specific item that is not formatted properly.

For Each itm As ListViewItem In itms '// loop thru all itms in Array.
            Try
                With itm.SubItems(1).Text '// check Column2.Text
                    If CInt(.Substring(0, .IndexOf("/"))) = CInt(selCoolMonth) Then '// get all text prior to the first "/".
                        selCoolListView.Items.Add(itm) '// if a match, add to ListView.
                    End If
                End With
            Catch ex As Exception
                ' MsgBox(ex.Message)
            End Try
        Next

nice

thanks alot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.