ListView in VB.net

Discussion in 'Visual Basic ( VB )' started by khwo, Jul 7, 2006.

  1. khwo

    khwo New Member

    Joined:
    Jul 6, 2006
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Hi all,

    I facing a problem with listview now, now I have data in the listview, when I click on the header of the column1, the search key will be point to column1. Mean that user will search what ever data in column1. When user click on the column2 then the search key will point to column2 no longer in column1 at all. For example, I have 3 column in my listview, 1) Employee No, 2) First Name 3) Second Name, when user click on the header of Employee No, user only can search for employee no not for first name and second name, by the way, user click on the header of first name, the user sure only can search for first name, and no more for employee no and also not for second name. Can anyone help me on this? Thanks.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Just have a variable which denotes the column name to be searched upon and in the header click event set it to appropriate value and when searching use the variable to your advantage.
     
  3. khwo

    khwo New Member

    Joined:
    Jul 6, 2006
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Hi All,

    I’m using the following coding for my searching function at listview, but I facing some problem here, if I use this code I only able to search the item at column 0 for the listview. But for my case, I want to let user click on the header of the column then the user only can key in the data for that column they select, what mean is if user click on the column 0 at the header of the listview then user only can search what ever data appear at the column 0 for the listview. As well for column 1, column 2 for the listview. The following coding only allow me to search the data at column 0 even I use the select case for the column click. What mistake I have made? Can anyone give me some advice on this? Thanks.

    This is my coding for the searching function at lisview:-
    Code:
    Private Sub ListView_Master_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView_Master.ColumnClick
    
            Dim Search_Code As String
            Dim exactMatch As Boolean
            Dim mySearchText As String
    
            Select Case e.Column
                Case 0 'column one BOM ID 
    
                    'MsgBox(e.Column)
    
                Case 1 'column two Cust Part # = BOM
    
                    MsgBox(e.Column)
    
                    mySearchText = Trim(InputBox("Please enter your Customer Part #", "Search Product Master Entry Data"))
    
                    'For Each itm As ListViewItem In ListView_Master.Items
                    For Each itm As ListViewItem In ListView_Master.Items
                        If exactMatch Then
                            If itm.Text = mySearchText Then
                                ' an exact match was found ...
                                MsgBox("Exact")
                            End If
                        Else
                            mySearchText &= "*"
                            If itm.Text Like mySearchText Then
                                ' a partial match was found ...
                                MsgBox("Partial")
                                'ListView_Master.Select()
                                'ListView_Master.Focus()
                            End If
                        End If
                    Next
    
                Case 2 'column three Child Part#A = CodeAChild Part#B = CodeB
                        MsgBox(e.Column)
    
                Case 3 'column three Child Part#B = CodeB
                        MsgBox(e.Column)
    
            End Select
    
        End Sub
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Refer to thread [thread=1010]ListView in VB.Net[/thread].
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice