RadComboBox CheckedItems is always zero

6 posts, 0 answers
  1. Zach
    Zach avatar
    11 posts
    Member since:
    Jul 2014

    Posted 19 Aug 2014 Link to this post

    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!
  2. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 22 Aug 2014 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dan
    Dan avatar
    2 posts
    Member since:
    Jun 2016

    Posted 23 Jun in reply to Nencho Link to this post

    Was this ever resolved? My CHECKEDITEMS.COUNT always return 0 no matter how many items I checked
  5. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 28 Jun Link to this post

    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.
  6. Zach
    Zach avatar
    11 posts
    Member since:
    Jul 2014

    Posted 28 Jun Link to this post

    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

  7. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 30 Jun Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017