This is a migrated thread and some comments may be shown as answers.

Hidden items showing empty space

7 Answers 292 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Scott Steinman
Top achievements
Rank 1
Scott Steinman asked on 19 Jan 2010, 01:34 AM
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.

7 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 21 Jan 2010, 12:39 PM
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.
0
Scott Steinman
Top achievements
Rank 1
answered on 21 Jan 2010, 03:07 PM
Thank you, Victor.  I'll give this a try.
0
Scott Steinman
Top achievements
Rank 1
answered on 24 Jan 2010, 01:57 AM
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?
0
Victor
Telerik team
answered on 25 Jan 2010, 10:11 AM
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.
0
Scott Steinman
Top achievements
Rank 1
answered on 26 Jan 2010, 04:19 AM
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.
0
Accepted
Victor
Telerik team
answered on 26 Jan 2010, 08:56 AM
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.
0
Scott Steinman
Top achievements
Rank 1
answered on 27 Jan 2010, 03:51 AM
That did it. Thank you very much.  My user interface looks great and my client is extremely happy with it.
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Scott Steinman
Top achievements
Rank 1
Answers by
Victor
Telerik team
Scott Steinman
Top achievements
Rank 1
Share this question
or