in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

ComboBox Functionality

Last post 01-28-2008 12:37 PM by C1_GregL. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-16-2008 5:20 PM

    ComboBox Functionality

    My environment is Visual Studio 2008. I know there will be an update coming on sometime around February but haven't had any problems and have tried in VS2005 as well.

    I want to do this in code and not in the designer as well with C#.

    • I'm working with the C1ComboBox control.
    • I have seven columns of data in the dropdown and is about 10,000 items long.
      • First off, yes I need all that data but will be filtering it as much as I can.
    • I can type ahead and it will pull the information from the first column.

    First, how would I go about also being able to search the second and the seventh column of data?

    Second, is there a way to say automatically filter out the items that don't meet the criteria as the end user is typing them? For example, if I have three rows with One, Two, and Three as my row item and type T is there a way to filter so only Two and Three show in the list?

    Thanks, John

     

  • 01-18-2008 3:25 PM In reply to

    • C1_GregL
    • Top 10 Contributor
    • Joined on 06-11-2007
    • Pittsburgh PA
    • Posts 500

    Re: ComboBox Functionality

    1. You can "search" any column, however you can only display a value from 1 column.  The DisplayMember property controls which column is displayed in the textbox, and therefore determines which column to base the autocompletion on.

    2. If your data binding has a BindingSource object you can set the filter property (see sample).  The filter can be applied to any number of columns.

    this.composerBindingSource.Filter = c1Combo1.DisplayMember + " LIKE '" + c1Combo1.Text + "%'";

    I've attached a sample that filters a C1Combo as keys are typed.

    -Greg

    Filed under: ,
  • 01-25-2008 8:32 PM In reply to

    Re: ComboBox Functionality

    The code works great if I use your sample but when I try doing it with the C1Combo it doesn't have the Filter as a valid option. My combo box isn't DataBound and am adding the rows through code. Is there a way to do it this way? Thanks, John

  • 01-28-2008 12:37 PM In reply to

    • C1_GregL
    • Top 10 Contributor
    • Joined on 06-11-2007
    • Pittsburgh PA
    • Posts 500

    Re: ComboBox Functionality

    The combo must be bound for the filter to work because the filter functionality is actually coming from the BindingSource and not the C1Combo.  But if you're adding unbound data through the AddItem method, you can replace this with a DataTable. 

    First add all the data to a DataTable and bind it to your C1Combo.  Add a BindingSource object to your form.  Then you set the BindingSource.Datasource = DataTable, and then C1Combo.DataSource = BindingSource. 

    See my new sample, but from there it's the same as the original sample.

    Regards,
    Greg

    Filed under: ,
Page 1 of 1 (4 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.