ComboBox: ReadOnly - My solution

5 posts, 0 answers
  1. Foudhil yasser
    Foudhil yasser avatar
    2 posts
    Member since:
    Oct 2009

    Posted 16 Nov 2009 Link to this post

    Hello all,
    I want to make ComboBox Readonly, i don't find a good Solution in the forum.
    I don't to use Skin...
    So
    I implemented a simple code !!! that i maked with help on demo:
                if (ZoneText is RadComboBox)  
                {  
                    ((RadComboBox)ZoneText).EnableViewState = false;  
                    if (mode == ModeEdit.ADD)  
                    {  
                        ((RadComboBox)ZoneText).BackColor = Color.White;  
                        ((RadComboBox)ZoneText).ShowToggleImage = true;  
                        //((RadComboBox)ZoneText).ShowDropDownOnTextboxClick = true;  
                        //((RadComboBox)ZoneText).ChangeTextOnKeyBoardNavigation = true;  
                        ((RadComboBox)ZoneText).OnClientKeyPressing = "";  
                        ((RadComboBox)ZoneText).OnClientDropDownOpening = "";  
                        ((RadComboBox)ZoneText).EnableTextSelection = true;  
     
                    }  
                    if (mode == ModeEdit.BROWSE)  
                    {  
                        ((RadComboBox)ZoneText).BackColor = Color.FromName("#E6E6E6");  
                        ((RadComboBox)ZoneText).ShowToggleImage = false;  
                        //((RadComboBox)ZoneText).ShowDropDownOnTextboxClick = false;  
                        //((RadComboBox)ZoneText).ChangeTextOnKeyBoardNavigation = false;  
                        ((RadComboBox)ZoneText).OnClientKeyPressing = "CancelKeyPress";  
                        ((RadComboBox)ZoneText).OnClientDropDownOpening = "CancelDropDown";  
                        ((RadComboBox)ZoneText).EnableTextSelection = false;  
     
                    }  
                    if (mode == ModeEdit.EDIT)  
                    {  
                        ((RadComboBox)ZoneText).BackColor = Color.White;  
                        ((RadComboBox)ZoneText).ShowToggleImage = true;  
                        //((RadComboBox)ZoneText).ShowDropDownOnTextboxClick = true;  
                        //((RadComboBox)ZoneText).ChangeTextOnKeyBoardNavigation = true;  
                        ((RadComboBox)ZoneText).OnClientKeyPressing = "";  
                        ((RadComboBox)ZoneText).OnClientDropDownOpening = "";  
                        ((RadComboBox)ZoneText).EnableTextSelection = true;  
     
                    }  
                } 
        public enum ModeEdit  
        {  
            ADD,  
            EDIT,  
            BROWSE  
        } 
    and finnaly
    i make 2 simple function JS !!!

    <script type="text/javascript">  
     
        function CancelDropDown(sender, eventArgs) {          
             eventArgs.set_cancel(true);  
        }    
     
        function CancelKeyPress(sender, eventArgs)  
        {  

            eventArgs.get_domEvent().keyCode =

    null;

        }  
    </script> 

    Code not complexe, but make combo like textBox,
    enjoy!!!!
  2. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 28 Jan 2011 Link to this post

    Came to this thread looking for an elegant solution to the telerik controls: DropDown, CheckBox, DateTimePick, etc. Want to have a readonly functionality implemented in them. Marking them Enabled = False is the most ugly solution. The above mentioned solution is for ASP.net. I required WinForms.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 31 Jan 2011 Link to this post

    Hi Hassan,

    Could you please post your question in the WinForms forums here?

    Kind regards,
    Yana
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  5. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 31 Jan 2011 Link to this post

    I thought this was the WinForms. I have posted to the correct sub-heading: Read-Only for all Editors
  6. Adrian
    Adrian avatar
    14 posts
    Member since:
    Apr 2010

    Posted 22 May 2012 Link to this post

    this works quite okay, but to hide the borders do in addition following:

    in .cs:
    ((RadComboBox)ZoneText).CssClass = "RadComboBox_Default_disabled";

    in .aspx:
    ...
        <style type="text/css">
        div.RadComboBox_Default_disabled .rcbInputCellLeft,
        div.RadComboBox_Default_disabled .rcbInputCellRight,
        div.RadComboBox_Default_disabled .rcbArrowCellLeft,
        div.RadComboBox_Default_disabled .rcbArrowCellRight
        {
            background-image: none;
            padding-left: 0px;
        }
    ...


        </style>
Back to Top
UI for WinForms is Visual Studio 2017 Ready