CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2002
    Location
    Germany
    Posts
    340

    Combo Box issue: Do not show an item

    Hi everyone,


    I have a data bound combo box as follows:

    Code:
    m_supplierList.DataSource = database.Tables[0];
    m_supplierList.DisplayMember = "Name";
    m_supplierList.ValueMember = "ID";
    Everything is fine except that there is one particular item that I do not want shown in the box. So, it should still be data bound but one item that I can reference by name or id should not be shown or be disabled.

    Does anyone know how I can do this? I tried doing it through the items collection in the same method but that does not seem to work.

    Thanks,
    xarg

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Combo Box issue: Do not show an item

    There aren't many choices. You either remove the items from the combo box or modify the collection.

    Since generally it's good programming to separate the presentation from the data, you may want to opt for modifying the collection (i.e. copying only the items you need into a new collection) and then bind it to the control. This approach keeps your UI code simple and keeps the collection manipulation in the data layer.

  3. #3
    Join Date
    Aug 2007
    Location
    Minneapolis
    Posts
    155

    Re: Combo Box issue: Do not show an item

    Arjay makes a very good point but it could be a little bit of work, depending on the scenario. I've run into similar situations and found it simpler to add a preventive validation after the fact. . .

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Combo Box issue: Do not show an item

    Can you set the column width to 0 to hide it?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Combo Box issue: Do not show an item

    Quote Originally Posted by trenches
    Arjay makes a very good point but it could be a little bit of work, depending on the scenario. I've run into similar situations and found it simpler to add a preventive validation after the fact. . .
    I have had similar problem with a combobox, where all the actual employees are to be shown, but after a while I also have employees in that list which are no longer working for me. For different other reaons I cannot delete them in the database. I solved this very simple adding a column to the database which refers a boolean named 'actual' And this way a simple sql Query allows to only show that employees which are still working for our company. So maybe if you can alter your sql maybe simple excluding the ID of the unwanted item in the query
    something like Select * From xyTab where ID > value oR ID < value
    and then you bind the resulting recordset to your comobox
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

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

Featured