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

ComboBox: ReadOnly - My solution

4 Answers 238 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Foudhil yasser
Top achievements
Rank 2
Foudhil yasser asked on 16 Nov 2009, 02:02 PM
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!!!!

4 Answers, 1 is accepted

Sort by
0
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
answered on 28 Jan 2011, 08:28 PM
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.
0
Yana
Telerik team
answered on 31 Jan 2011, 10:41 AM
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.
0
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
answered on 31 Jan 2011, 11:19 AM
I thought this was the WinForms. I have posted to the correct sub-heading: Read-Only for all Editors
0
Adrian
Top achievements
Rank 2
answered on 22 May 2012, 01:19 PM
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>
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Foudhil yasser
Top achievements
Rank 2
Answers by
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Iron
Yana
Telerik team
Adrian
Top achievements
Rank 2
Share this question
or