Results 1 to 9 of 9

Thread: check for duplicate items in combobox

Hybrid View

  1. #1
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: check for duplicate items in combobox

    Quote Originally Posted by kulrom
    but why ... i've used DISTINCT many times before and i never noted any issue about that ... then i'm wondering why you recommend not using of DISTINCT?
    DISTINCT and GROUP BY have a place in SQL - that's for sure.

    But I've seen too many people develop a poor join - resulting in "phantom" duplicate rows and then using DISTINCT to get rid of them.

    In the past 3 years we have developed nearly 1000 STORED PROCEDURES and I cannot remember the time we used SELECT DISTINCT.

    Prior to MS SQL SERVER 2000, SELECT DISTINCT would build the resultset and then apply the DISTINCT upon it - GROUP BY was better. Now they are the same.

    And as you can see from the reply - DISTINCT isn't going to work in this case either.

    As for the DUPLICATE issue in the COMBO box - search around the FORUM, I've seen API tricks on COMBOBOXES that get rid of duplicates...

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    66

    Re: check for duplicate items in combobox

    Quote Originally Posted by szlamany
    As for the DUPLICATE issue in the COMBO box - search around the FORUM, I've seen API tricks on COMBOBOXES that get rid of duplicates...
    I searched the forums, but i can't find it. what keyword should i use?

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: check for duplicate items in combobox

    Quote Originally Posted by digita
    I searched the forums, but i can't find it. what keyword should i use?
    It was tough to find - but here's a link:

    Find a string in a combobox with API

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    66

    Re: check for duplicate items in combobox

    what does it do, because i don't inderstand it, and how do i use it?

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    4.                                                                         ByVal wMsg As Long, _
    5.                                                                         ByVal wParam As Long, _
    6.                                                                         lParam As Any) _
    7.                                                                         As Long
    8.  
    9. Private Const CB_ERR = (-1)
    10. Private Const CB_FINDSTRING = &H14C
    11. Private Const CB_FINDSTRINGEXACT = &H158
    12.  
    13. Private Function FindItemByString(cmb As ComboBox, ByVal SearchFor As String, Optional FindExact As Boolean = False) As Integer
    14.     FindItemByString = CInt(SendMessage(cmb.hwnd, IIf(FindExact, CB_FINDSTRINGEXACT, CB_FINDSTRING), _
    15.                             CB_ERR, ByVal SearchFor))
    16. End Function

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: check for duplicate items in combobox

    Hey, that looks very simlar to my code I posted a long time ago.

    What it does is use the sendmessage api to find in the passed combo box (depending on the exact or
    like parameter being passed) a item with the same (exact or partial matching) combo item text. Then if it
    finds it it will return the index integer of the found item.


    VB Code:
    1. 'Usage for exact match:
    2. Private Sub Command1_Click()
    3.     Combo1.ListIndex = FindItemByString(Combo1, Combo1.Text, True)
    4. End Sub
    If its not found then the function returns a -1 which will not give the combo an error but rather a no
    selection depending on the Style of the combo box.

    HTH
    Last edited by RobDog888; Feb 13th, 2005 at 01:12 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width