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

How to disable and hide a single checkbox?

3 Answers 641 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 13 Mar 2012, 11:04 PM
I am receiving a dictionary which I am binding to the combobox control. I wrote a loop that iterates through the items collection and changes some flagged items to a separator item. The problem is, if checkboxes are enabled, the seperator also receives a checkbox which sort of defeats the functionality. Is there something I could add to my loop that will disable the checkbox on these items?

Here is an example of the code that I'm using to create the seperators:

public static void FormatList(ref RadComboBox assignees)
{
    for (int i = 0; i < assignees.Items.Count; i++)
    {
        if (assignees.Items[i].Text == "people")
        {
            assignees.Items[i] = new Telerik.Web.UI.RadComboBoxItem("Assign to Person:");
            assignees.Items[i].IsSeparator = true;                   
        }
        if (assignees.Items[i].Text == "group")
        {
            assignees.Items[i] = new Telerik.Web.UI.RadComboBoxItem("Assign to Group:");
            assignees.Items[i].IsSeparator = true;
        }
    }
}

3 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 14 Mar 2012, 01:37 PM
Hello Jeremy,

That looks like a strange bug that should be fixed by Telerik, but for the time being you could add a css class to your page and add it to your separator items so it hides the checkbox.

.hideGroupCheckBox .rcbCheckBox
{
    display: none;
}

I hope that helps.
0
Jeremy
Top achievements
Rank 1
answered on 15 Mar 2012, 03:22 PM
Thanks, that seems like it would work. But would that still work if I'm not using an ItemTemplate? In the meanwhile, I went in and took care of it with some javascript:

<script type="text/javascript">
        function OnClientDropDownOpening(sender, eventArgs) {
            var items = sender.get_items(); for (i = 0; i < items.get_count(); i++) {
                if (items.getItem(i).get_isSeparator()) {
                    var checkbox = items.getItem(i).get_checkBoxElement();
                    checkbox.style.display = "none";
                }
            }
        }
 </script>


Then added it to the dropdown event:

<rad:RadComboBox runat="server" ID="cboAssignees" OnClientDropDownOpening="OnClientDropDownOpening" />

0
Kalina
Telerik team
answered on 19 Mar 2012, 05:35 PM
Hello Jeremy,

You can try this style:
<style type="text/css">   
    .rcbSeparator input { display: none }
</style>

All the best,
Kalina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ComboBox
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Jeremy
Top achievements
Rank 1
Kalina
Telerik team
Share this question
or