Results 1 to 2 of 2

Thread: yet again about combobox suggest any substring

  1. #1
    ridhwaans is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0
    Join Date
    Jun 2012
    Posts
    33
    Reputation
    14

    yet again about combobox suggest any substring

    as you know, the combobox autocompletemode suggests items that start with the specified string, and not contain

    Code:
    Public Class Form1
        Private AllNames As New DataTable()
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            AllNames.Columns.Add("Name", GetType(String))
    
            For i As Integer = 0 To (ComboBox1.Items.Count - 1)
                AllNames.Rows.Add(ComboBox1.Items(i).ToString)
            Next
        End Sub
    
        Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
            Dim name As String = String.Format("{0}{1}", ComboBox1.Text, e.KeyChar.ToString())
            MsgBox(name)
            'join previous text and new pressed char
            Dim rows As DataRow() = AllNames.Select(String.Format("Name LIKE '%{0}%'", name))
    
            Dim filteredTable As DataTable = AllNames.Clone()
            For Each r As DataRow In rows
                filteredTable.ImportRow(r)
            Next
            ComboBox1.DataSource = Nothing
            ComboBox1.DataSource = filteredTable.DefaultView
            ComboBox1.DisplayMember = "Name"
        End Sub
    End Class

    The datatable AllNames has only 1 field ("Names") and rows obtained from combobox items collection

    Code:
    Aaron Alex
    Aaron Bud
    Aarts Jan
    Abas S.J.
    Abbey Michael
    Abdelguerfi Mahdi
    Abel David
    Abel Peter
    Abelson Amanda
    Baase Sara
    Baber Robert Laurence
    Babet Bruneau
    Bache Richard
    Back Thomas
    Bacon Jean
    Bacon Jonathan
    Bacon Jonathan P.
    Baczewski Philip
    Badgett Tom
    Cable Doris B.
    Cabrera Luis-Felipe
    Cabrera Malu
    Cady Dorothy
    Cady Dorothy L.
    Caffarelli Fabrizio
    Caffrey Martin
    Cahape Pat
    Cahn Dudley D.
    Cairoli R.
    Dachslager Howard L.
    Daconta Michael C.
    Dahleh Munther A.
    Dahmen H.D.
    Dahr Michael
    Dalang Robert C.
    Dalgleish Fred
    Dalglesh Fred
    Dallas Alastair W.
    Eagan John
    Eager Bill
    Earnshaw Rae
    Eastman Richard
    Eaton John K.
    Eaton Laura
    Ebenau Robert G.
    Eberhard Anton A.
    Ebert David S.
    Eccles Margaret
    Eckel B.
    Fabbri Tony
    Fairclough J.
    Faison Ted
    Faith Irene
    Falby Walter
    Falk Jack
    Falkenberg E.D.
    Falkner Mike
    Fally Veronique
    Falster Peter
    Farkas David
    Farley Tim
    Farmer Lesley S.J.
    Farnell Brenda
    Farrell Ann M.
    Farrell James Alan
    Farrell Joyce M.
    Farrell Rob
    Fatah Burhan
    Faudemay P.
    Gal Tomas
    Galambos Emery
    Galdeiri Beth
    Gale Thornton
    Gallagher Richard S.
    Gallagher Simon
    Gallaire Herve
    Gallaire Herve; Minker Jack and Nicolas Jean Ma
    Gallmeister Bill O.
    Hahn Brian D.
    Hahn Harley
    Haigh Jim
    Hains Gaetan
    Hakala David
    Hakim Jack
    Halang W.A.
    Hale Robert L
    Ian Devling
    Ichbiah J.
    Ichikawa Tadao
    Ing Julie
    Ingalsbe L.
    Ingalsbe Lon
    Ingham Kenneth
    Inglis Jim
    Inman Don
    Jacobson Jean
    Jacobson Linda
    Jacobson norma
    Jacobson Reed
    Jacobson Steve
    Jacso Peter
    Jaeschke Rex
    Jagannathan R.
    Jagannathan Suresh
    Jagger Alice
    Kalman David M.
    Kalman Ted
    Kalmon Ted
    Kaluzniacky Eugene
    Kambayashi Y.
    Kambayashi Yahiko
    Kamin Johnathan
    Kamin Jonathan
    Kamin Sam
    Labarre James E.
    Laborde Dominique
    Ladd Scott Robert
    Ladymon Robert F.
    Laffra C.
    Lafore Robert
    Lafore Robert W.
    Lafreniere Lori
    Lahey Thomas M.
    Lai David A.
    Lajoie Susanne P.
    Lake Matthew
    MacKay Jeff
    MacKay Pierre
    MacKenroth D.R.
    MacKenzie I. Scott
    MacKerle J.
    MacLean Roy
    MacLeod Don
    MacNelly Jeff
    MacQueen Dave
    MacVittie Donald W.
    MacVittie Lori A.
    Nahrstedt Klara
    Naiditch David
    Naiman Arthur
    Nait Abdallah Areski
    Nakamura Shoichiro
    Nameroff Steven
    Nance Barry
    Nance Douglas W.
    Nanfarra Frank
    Nanney T.
    O'Donnell Craig
    O'Donnell John T.
    O'Donnell Peggy
    O'Donnell Sandra Martin
    Palamidese Patrizia
    Palle Ibsen
    Palmer Ian C.
    Palmer Michael J.
    Palmer R.
    Palmer Roger
    Palmer Roger C.
    Palmer Scott
    Quach e
    Quasney James S.
    Quilici Alexander E.
    Quinn Bob
    Quirk Kent
    Quittner Pal
    Qureshi A.H.
    Rahimi S.
    Rahmel Dan
    Rahmel Ron
    Raiha Kari-Jouko
    Rains Alvin L.
    Raitt David I.
    Raker Dan
    Sadri F.
    Sagiv Yehoshua
    Sagman Stephen W.
    Sagman Steve
    Sahni Sartaj
    Saigal Romesh
    Saini Atul
    Saint-Dizier Patrick
    Saitta L.
    Sajo Andras
    Saks Dan
    Tan Poh Lee
    Tanaka Hidehiko
    Tanaka Katsumi
    Tanca L.
    Tanenbaum Andrew S.
    Tang Victor
    Tanik Murat
    Tanik Murat M.
    Uno Kimio
    Unruh Betty
    Unruh Eric L.
    Unseld Sigrid
    Urbanek Chris
    Urbanek Waldemar
    Uren Emmanuel
    Utvich Michael
    Utz James
    Van Den Heuvel Theo
    Van Der Gaag Linda
    Van Der Lans Rick F.
    Van Der Linden Peter
    Van Duyn Julia
    Van Dyk John A.
    Van Dyke Steven L.
    Van Gilluwe Frank
    Van Gucht D.
    Van Halteren Hans
    Van Hentenryck Pascal
    Wagoner Kathleen P.
    Wagstaff Sean
    Wah Benjamin W.
    Wahl Bernt
    Waite Mitchell
    Wakeling David
    Wakeman Lois
    Walden Jeff
    Walden Kim
    Xie M.
    Yao S.
    Yao S. B.
    Yarmish Rina
    Yellick Craig
    Yeralan Sencer
    Yerkey A. Neil
    Yester Michael
    Yocom Jeff
    Yonezawa Akinori
    Zack William H.
    Zehna Peter W.
    Zeleznikow J.
    Zelkowitz Marvin V.
    Zenreich Alan
    Zernik Uri
    Ziarko Wojciech P.
    Zicari Roberto
    So, if the user types a first name or last name regardless, the combobox is supposed to suggest the names containing that substring
    But the code doesnt seem to work, and sometimes I get a protected memory access violation exception

    Any help?

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,341
    Reputation
    1543
    I don't really see why you're changing the bindings every time. Why not just bind the DataTable to the ComboBox once to start with and then set its DefaultView.RowFilter each time?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking