Readonly combobox

4 posts, 0 answers
  1. Max
    Max avatar
    34 posts
    Member since:
    Dec 2011

    Posted 24 Dec 2012 Link to this post

    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".
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Dec 2012 Link to this post

    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.
  3. Max
    Max avatar
    34 posts
    Member since:
    Dec 2011

    Posted 24 Dec 2012 Link to this post

    Anyway to do that in the code-behind? In actual scenario there might be >1 items (2, 3 or many more).
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Dec 2012 Link to this post

    Hi,

    Try the following code to achieve your scenario.

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

    Hope this helps.

    Thanks,
    Shinu.
Back to Top