Hidden items showing empty space

8 posts, 1 answers
  1. Scott Steinman
    Scott Steinman avatar
    5 posts
    Member since:
    Jan 2010

    Posted 18 Jan 2010 Link to this post

    I have a RadComboBox displaying 70 user options (yes, it's a lot, but it's needed to replicate an electronic device that has all of these settings).  To simplify the option selection for users, I'm using a second RadComboBox to allow the user to see only subsets of the 70 options in the first RadComboBox.  Whether I use the Hidden or Collapsed visibility settings for the items I wish to hide, an empty space is shown in the drop-down list so the list is just as long, but mostly empty.  Is this the intended behavior of the RadComboBox, or have I set this up incorrectly?  Please don't tell me I supposed to load separate collections of items and have different selected item event code for each subset.

    Thanks in advance for your help.
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 21 Jan 2010 Link to this post

    Hello Scott Steinman,

    Thank you for writing. Since your requirement is not to have multiple collections you can consider using two DataView objects. In the DataView you can set a filter expression on the combo box that displays a subset of items. Here is how you can do this:

    public partial class Form1 : Form
    {
        DataTable mainTable = null;
        DataView subView = null;
        public Form1()
        {
            InitializeComponent();
     
            mainTable = this.CreateTable();
            subView = new DataView(mainTable);
     
            string displayMember = "Name";
            string valueMember = "Value";
     
            this.radComboBox1.DisplayMember = displayMember;
            this.radComboBox1.ValueMember = valueMember;
            this.radComboBox1.DataSource = mainTable.DefaultView;
     
            this.radComboBox2.DisplayMember = displayMember;
            this.radComboBox2.ValueMember = valueMember;
            this.radComboBox2.DataSource = subView;
        }
     
        private DataTable CreateTable()
        {
            DataTable result = new DataTable();
            result.Columns.Add(new DataColumn("Name", typeof(string)));
            result.Columns.Add(new DataColumn("Value", typeof(int)));
     
            for (int i = 0; i < 70; ++i)
            {
                DataRow row = result.NewRow();
                row["Name"] = i.ToString();
                row["Value"] = i;
                result.Rows.Add(row);
            }
     
            return result;
        }
     
        private void radComboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int value = (int)this.radComboBox1.SelectedValue;
     
            // Compose filter expression based on the selected value in the first combo box.
            // This is a rather silly filter but it serves the example. You can provide whaterver filter you need
            // provided it has the correct syntax. Look up the RowFilter property of DataView in the MSDN for details
            // on the syntax.
            string filter = "Value = " + value.ToString();
     
            this.subView.RowFilter = filter;
        }
    }

    Please write again if you need further assistance.

    Sincerely yours,

    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Scott Steinman
    Scott Steinman avatar
    5 posts
    Member since:
    Jan 2010

    Posted 21 Jan 2010 Link to this post

    Thank you, Victor.  I'll give this a try.
  5. Scott Steinman
    Scott Steinman avatar
    5 posts
    Member since:
    Jan 2010

    Posted 23 Jan 2010 Link to this post

    Victor,

    Unfortunately, your suggestion did not work.  The ComboBox still shows the items that should be filtered out, even though they are disabled.  Do I need to build separate collections for each subset of items that I wish to display, then reset the ComboBox's data source to one of these collections?
  6. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 25 Jan 2010 Link to this post

    Hello Scott Steinman,

    I have attached a sample application which demonstrates the functionality. The second combo box will display only the item that is selected in the first combo. Setting the RowFilter to "" will cause it to display all items again. Please write again if you need further assistance.

    Sincerely yours,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Scott Steinman
    Scott Steinman avatar
    5 posts
    Member since:
    Jan 2010

    Posted 25 Jan 2010 Link to this post

    Victor,

    This is working in my code, and I've read the MSDN documentation on RowFilters to make sure that I understand the code.  One additional question: When working with a data table like this, is there still a way to access the items' description property or enabled property?

    Thank you once again.  Your help has been very valuable.
  8. Answer
    Victor
    Admin
    Victor avatar
    1351 posts

    Posted 26 Jan 2010 Link to this post

    Hi Scott Steinman,

    Thank you for writing. Please provide more details on which items are you referring to. RadComboBoxItem objects that are inside RadComboBox or the underlaying data items? RadComboBoxItems are always accessible through the Items collection of RadComboBox no matter what your datasource is. If you need to provide more data you can extend the DataTable schema and provide more columns which will hold data in addition to the DisplayMember value and the ValueMember value. The drawback of the approach I am suggesting is that you have data object between your UI and data layer which needs some degree of synchronization, the benefit is that you get filtering for free.

    Retrieving the information later can be done via RadComboBoxItem.DataItem property. This property will return a DataRow that you created which will have all the information you decided to store in it. Do not hesitate to write again if you need further assistance.

    Sincerely yours,
    Victor
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Scott Steinman
    Scott Steinman avatar
    5 posts
    Member since:
    Jan 2010

    Posted 26 Jan 2010 Link to this post

    That did it. Thank you very much.  My user interface looks great and my client is extremely happy with it.
Back to Top
UI for WinForms is Visual Studio 2017 Ready