CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Custom Combo Box

    Hello all,

    I need Hinsights and also advices about what I'd like to do. I would like to have a custom combo boxes in which I insert instances of certain class I made. I want that combo box to show only items that has a certain value in a certain field in my class. Is there a way to do such a filter to a combo box or it's just showing everything in its list ? If it's possible to do that, I would like to know what to look for in the events and or methods I should work on to be able to change the behavior of the default "SHOWING" of items.

    Thanks in Advance.
    Nicolas Bohemier

  2. #2
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892

    Arrow Re: Custom Combo Box

    You can override the OnMeasureItem and OnDrawItem... or you can create a custom ComboBox with an internal private array that holds all of the data, and the public collection could be updated to hold the filtered items.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  3. #3
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Re: Custom Combo Box

    Sounds like a plan. Thank you
    Nicolas Bohemier

  4. #4
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Re: Custom Combo Box

    I expressed myself incorrectly... Here's the Behavior I would like my Combo Box to have..



    I have a database with secondary data ( data that are parents to other data ). That parent table has a field called Activated and the value is true false.

    Here's what I'd like to do. Whenever I load an old data, I would like to be able to show all entry but whenever the User wants to specify the value of this combo box, I would like to show only Activated Items in the dropdownlist. I wanna use a list because I don't want to let the user to type in something. That table will never be big (I'm guessing 15 items max).

    I tried playing with the .Text property but it's not working.
    Nicolas Bohemier

  5. #5
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: Custom Combo Box

    I don't understand exactly how you want the user to select a value, but maybe this will help.

    You can use a DataView object. This object get a DataTable in the constructor, and it will show values from that table.

    In order to use it, here is a sample:
    Code:
    Dim dv As DataView = New DataView(myDataSet.Tables("MyTable"))
    comboBox1.DataSource = dv
    comboBox1.DisplayMember = "Name" 'Will display the Name column of MyTable table.
    comboBox1.ValueMember = "Id" 'The SelectedValue property will be the Id
    Set the DropDownStyle to DropDownList if you don't want the user to type values.

    Now for the interesting part. The DataView object has a Filter property. by setting it you can manipulate with the list that is shown when the user sees the drop down.
    Code:
    dv.Filter = "" ' No Filter
    'Or
    dv.Filter = "Activated = True" ' You can use "Activated" (boolean)
    I hope this helps.

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