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

Remove checkbox from first item in combobox

4 Answers 472 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Craig Wallace
Top achievements
Rank 1
Craig Wallace asked on 13 Jan 2014, 03:27 PM
Hi,

Telerik.Web.UI v2013.3.1015.40

I have a simple usage scenario for a RadComboBox:

<telerik:RadComboBox ID="cbProducts" runat="server" Width="250px"
                    DataSourceID="dsProducts" DataTextField="ProductName"
                    DataValueField="ProductID" AppendDataBoundItems="true" CheckBoxes="True"
                    onitemchecked="dlProducts_ItemChecked" AutoPostBack="true">
                        <Items>
                            <telerik:radcomboboxitem Text="-- Select --" Value="" />
                        </Items>
                </telerik:RadComboBox>

This allows the user to select multiple products by using the checkboxes.  The problem is, it also allows the user to check the default '-- Select --' item that I have added as it also shows a checkbox, and there seems to be no 'ShowCheckbox' property on RadComboBoxItem that I can toggle.

How can I remove the checkbox on my first item in the RadComboBox?

Thanks.

4 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 13 Jan 2014, 05:22 PM
Hello Craig,

You can use the following JavaScript code to accomplish this:

<script type="text/javascript">
    function comboLoad(sender) {
        var item = sender.get_items().getItem(0),
            checkBoxElement = item.get_checkBoxElement(),
            itemParent = checkBoxElement.parentNode;
 
            itemParent.removeChild(checkBoxElement);
    }
 
</script>
 
<telerik:RadComboBox runat="server" CheckBoxes="true" ID="ComboBox1" OnClientLoad="comboLoad">
    <Items>
        <telerik:RadComboBoxItem Text="Select" />
        <telerik:RadComboBoxItem Text="Text1" />
    </Items>
</telerik:RadComboBox>

I hope that this helps.

Regards,
Genady Sergeev
Telerik
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 the blog feed now.
0
Craig Wallace
Top achievements
Rank 1
answered on 14 Jan 2014, 09:21 AM
Hi Genady,

Thanks.  There were a couple of typos in your code but I cleaned them up and the checkbox is removed.

function comboLoad(sender) {
            var item = sender.get_items().getItem(0);
            checkBoxElement = item.get_checkBoxElement();
            itemParent = checkBoxElement.parentNode;
            itemParent.removeChild(checkBoxElement);
        }

There is an additional problem now.  If I click on '-- Select --', it is shown as the dropdown text.  If I then tick one of the checkboxes, the control says that 2 items have been selected.  It's as if clicking on the first item still checks the checkbox.

Any ideas?

Craig
0
Genady Sergeev
Telerik team
answered on 16 Jan 2014, 04:48 PM
Hi Craig,

I am not reproducing the problem with the latest version of the controls therefore this might be a bug in the version that you use. Which one is it?


Regards,
Genady Sergeev
Telerik
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 the blog feed now.
0
jackson
Top achievements
Rank 1
answered on 13 Jan 2016, 01:10 PM

get the Separator Text and  set_checked as false.

function disableCheckOptionForSeparator() {
                var comboBox = $find("<%=RadComboBoxSites.ClientID %>");
                 
                var itemSiteSeparator = comboBox.findItemByText("-- Select --");
                if (itemSiteSeparator.get_isSeparator()) {
                    itemSiteSeparator.set_checked(false)
                }
 
                return true;
            }

Tags
ComboBox
Asked by
Craig Wallace
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Craig Wallace
Top achievements
Rank 1
jackson
Top achievements
Rank 1
Share this question
or