How to exclude duplicates in combo box?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: How to exclude duplicates in combo box?

  1. #1
    Flora Guest

    How to exclude duplicates in combo box?


    I have a problem with combo box. I wanted to populate a list of Customer ID
    to the combox box. I have the codes to do that. But I have duplicates of
    the IDs in the list. How can I exclude the duplicates?

    Thanks!

  2. #2
    George Lissauer Guest

    Re: How to exclude duplicates in combo box?

    You can search the listbox with this code to see if the item
    exists and then don't add it:
    http://www.vb2themax.com/Item.asp?Pa...odeBank&ID=225
    ....
    George
    GridLinx Software Programming Tools for VB Programmers
    http://www.gridlinx.com

    Flora wrote in message <3afa104c$1@news.devx.com>...
    >
    >I have a problem with combo box. I wanted to populate a list of Customer ID
    >to the combox box. I have the codes to do that. But I have duplicates of
    >the IDs in the list. How can I exclude the duplicates?
    >
    >Thanks!




  3. #3
    Robert Gelb Guest

    Re: How to exclude duplicates in combo box?

    There is nothing inherent in the listbox that will reject duplicates. You
    simply need to search the listbox for the ID before inserting an entry.

    --
    Robert Gelb
    www.vbRad.com
    Source, Tips, Tricks, Components

    "Flora" <stargaze233@netscape.net> wrote in message
    news:3afa104c$1@news.devx.com...
    >
    > I have a problem with combo box. I wanted to populate a list of Customer

    ID
    > to the combox box. I have the codes to do that. But I have duplicates of
    > the IDs in the list. How can I exclude the duplicates?
    >
    > Thanks!




  4. #4
    Ian Williams Guest

    Re: How to exclude duplicates in combo box?

    Flora

    Public Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, _
    lParam As Any) As Long

    Public Const Public Const CB_FINDSTRINGEXACT = &H158

    Sub AddUniqueToCombo(cmb As ComboBox, strItem As String)
    If SendMessage(cmb.hwnd, CB_FINDSTRINGEXACT, _
    -1&, ByVal strItem) = -1 Then cmb.AddItem strItem
    End Sub

    regards

    Ian

    ** invalid email address, change dk to denmark

    homepage http://www.kingsoft-denmark.com/
    Tips & Tricks page http://tips.kingsoft-denmark.com/

    "Flora" <stargaze233@netscape.net> wrote in message
    news:3afa104c$1@news.devx.com...
    >
    > I have a problem with combo box. I wanted to populate a list of Customer

    ID
    > to the combox box. I have the codes to do that. But I have duplicates of
    > the IDs in the list. How can I exclude the duplicates?
    >
    > Thanks!




  5. #5
    Jorge Bengalito Guest

    Re: How to exclude duplicates in combo box?


    "Flora" <stargaze233@netscape.net> wrote:
    >
    >I have a problem with combo box. I wanted to populate a list of Customer

    ID
    >to the combox box. I have the codes to do that. But I have duplicates of
    >the IDs in the list. How can I exclude the duplicates?
    >
    >Thanks!


    I think you are not seeing well the actual problem - a Customer ID table
    should never allow duplicate entries controled by an index on the ID field.
    With this aproach your problem would never happened.
    Jorge

  6. #6
    Dean Earley Guest

    Re: How to exclude duplicates in combo box?

    If you a filling it from an SQL query, you could try
    SELECT DISTINCT ID, Field FROM Table

    --
    Dean Earley (dean.earley@icode.co.uk)
    Assistant Developer

    iCode Systems
    "Flora" <stargaze233@netscape.net> wrote in message news:3afa104c$1@news.devx.com...
    >
    > I have a problem with combo box. I wanted to populate a list of Customer ID
    > to the combox box. I have the codes to do that. But I have duplicates of
    > the IDs in the list. How can I exclude the duplicates?
    >
    > Thanks!




  7. #7
    Ilyan Mishiyev Guest

    Re: How to exclude duplicates in combo box?


    If you use SELECT statement to get your records, use DISTINCT.
    If you want to exclude it on the client side, create array, and using loop,
    put all inserted values in this array. And every time you move in your insert,
    check if a new value is in array. If it is, skip, if not, add to array and
    to the combobox.

    "Flora" <stargaze233@netscape.net> wrote:
    >
    >I have a problem with combo box. I wanted to populate a list of Customer

    ID
    >to the combox box. I have the codes to do that. But I have duplicates of
    >the IDs in the list. How can I exclude the duplicates?
    >
    >Thanks!



  8. #8
    Matt Braden Guest

    Re: How to exclude duplicates in combo box?


    I would say the simplest way to avoid duplicates is to use the GROUP BY in
    your SQL statement such as "SELECT * FROM Customers GROUP BY Cust_ID". This
    will get rid of all of you duplicates.

    "Ilyan Mishiyev" <mishiyev@hotmail.com> wrote:
    >
    >If you use SELECT statement to get your records, use DISTINCT.
    >If you want to exclude it on the client side, create array, and using loop,
    >put all inserted values in this array. And every time you move in your insert,
    >check if a new value is in array. If it is, skip, if not, add to array and
    >to the combobox.
    >
    >"Flora" <stargaze233@netscape.net> wrote:
    >>
    >>I have a problem with combo box. I wanted to populate a list of Customer

    >ID
    >>to the combox box. I have the codes to do that. But I have duplicates of
    >>the IDs in the list. How can I exclude the duplicates?
    >>
    >>Thanks!

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center