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

Readonly combobox

3 Answers 208 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Max
Top achievements
Rank 1
Max asked on 24 Dec 2012, 07:57 AM
There are, say 2 items in a combobox. How do I set first item (visible for the user with icon and text) and prohibit selecting another item? So combobox should not expand and be "Read-only".

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Dec 2012, 10:04 AM
Hi,

Please try the following code snippet to set the first item selected and to prohibit selecting another item.

Javascript:
<script type="text/javascript">
   function OnClientDropDownOpening(sender, eventArgs)
   {
      if (sender.get_items().get_count() == 2)
       {
            eventArgs.set_cancel(true);
       }
    }
</script>

Thanks,
Shinu.
0
Max
Top achievements
Rank 1
answered on 24 Dec 2012, 10:07 AM
Anyway to do that in the code-behind? In actual scenario there might be >1 items (2, 3 or many more).
0
Shinu
Top achievements
Rank 2
answered on 26 Dec 2012, 07:02 AM
Hi,

Try the following code to achieve your scenario.

C#:
RadComboBox1.SelectedIndex = 1;
RadComboBox1.Enabled = false;

Hope this helps.

Thanks,
Shinu.
Tags
ComboBox
Asked by
Max
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Max
Top achievements
Rank 1
Share this question
or