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

RadComboBox CheckedItems is always zero

5 Answers 670 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Zach
Top achievements
Rank 1
Zach asked on 19 Aug 2014, 05:34 PM
I have a RadCombBox and RadButton like this:

<telerik:RadButton runat="server" id="btnPlantName" OnClick="btnPlantName_Click" Text="Filter"/><br />
        <label for="" class="filterElement">Plant Name: </label>
        <telerik:RadComboBox
            ID="RadComboBoxPlantName"
            DataSourceID="SqlPlantNameList"
            DataTextField="PlantName"
            DataValueField="PlantName"
            AppendDataBoundItems="true"
            runat="server"
            OnClientSelectedIndexChanged="PlantIndexChanged"
            class="filterElement" EnableLoadOnDemand="false"
            CheckBoxes="true" EnableCheckAllItemsCheckBox="true">            
        </telerik:RadComboBox>

And my code behind is set up like this: 

protected void btnPlantName_Click(object sender, EventArgs e)
{
   FilterByComboBox(RadComboBoxPlantName, "PlantName");
}
 
private void FilterByComboBox(RadComboBox box, string columnName)
        {
            var selectedItems = box.CheckedItems;
            List<string> values = new List<string>();
 
            if (selectedItems.Count != 0)
            {
                foreach (var item in selectedItems)
                    values.Add(item.Text);
 
                FilterColumnByMultipleValues(columnName, values.ToArray());
            }           
        }

When I step through the code, the event is fired properly, but box.CheckItems is always zero.  Why is this?  I need to be able to get all the values.

Thanks!

5 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 22 Aug 2014, 08:19 AM
Hello Zach,

The CheckedItems would return the collection of items of the RadComobBox, which have their checkboxes checked. Could you specify  If you need to access all items values, or only the checked ones?
If you need all of the items, you could access them using the Items collection -

var selectedItems = box.Items;



Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Dan
Top achievements
Rank 1
answered on 23 Jun 2016, 08:22 PM
Was this ever resolved? My CHECKEDITEMS.COUNT always return 0 no matter how many items I checked
0
Nencho
Telerik team
answered on 28 Jun 2016, 12:45 PM
Hello Dan,

Since I am not able to locally replicate the issue in question in this thread, when the LoadOnDemand feature is disabled, and as I can see you have already submitted a support ticket on the matter - I would suggest you to continue the correspondence in the support ticket.

Regards,
Nencho
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Zach
Top achievements
Rank 1
answered on 28 Jun 2016, 12:51 PM

Hey Dan,

I don't remember exactly where the problem was in the code that I posted, but here's an example of the code I've been using successfully:

01.<telerik:RadComboBox
02.    ID="RadComboBoxPlantName"
03.    runat="server"
04.    DropDownAutoWidth="Enabled"
05.    AllowCustomText="true"
06.    MarkFirstMatch="true"
07.    Filter="Contains"
08.    CheckBoxes="true">
09.</telerik:RadComboBox>

01.private void BindFilter()
02.{
03.    List<FilterLineItem> plants = _helper.GetPlants();
04. 
05.    RadComboBoxPlantName.Items.Clear();
06.    RadComboBoxPlantName.DataSource = plants;
07. 
08.    RadComboBoxPlantName.DataTextField = "Name"; //PlantName
09.    RadComboBoxPlantName.DataValueField = "ID"; //PlantID
10.    RadComboBoxPlantName.DataBind();
11.}
12. 
13.private List<int> GetSelectedPlants()
14.{
15.    if (RadComboBoxPlantName.CheckedItems.Count == 0)
16.        return new List<int> { -1 }; // -1 = All plants
17.    else
18.    {
19.        var plants = new List<int>();
20. 
21.        foreach (var plant in RadComboBoxPlantName.CheckedItems)
22.        {
23.            plants.Add(Convert.ToInt32(plant.Value));
24.        }
25. 
26.        return plants;
27.    }
28.}

Hope this helps

0
Nencho
Telerik team
answered on 30 Jun 2016, 10:07 AM
Hello Zach,

Thank you for sharing your solution with the community! Just a note on your implementation - the MarkFirstMatch (and Filtering) functionalities, are not supported along with the Checkboxes support.
However, if you fits your needs - you can still use it.

Regards,
Nencho
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
ComboBox
Asked by
Zach
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Dan
Top achievements
Rank 1
Zach
Top achievements
Rank 1
Share this question
or