Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a windows application that runs sql scripts. The scenario is that I have given user the option to use existing database that is there in system. Like:

Use existing Database: (checkbox)

If the user clicks on it, he will get a dropdownlist of database existing in the system.But, the problem is he can still edit in the Dropdownlist\textBox. Actually it is a combobox.
I wanted to disable the part where he/she can edit when the checkbox is checked.

For reference :

C#
private void chkUseExistingDb_CheckStateChanged(object sender, EventArgs e)
       {
           CheckBox cbUseExistingDatabase = (sender as CheckBox);
           bool IsChecked = cbUseExistingDatabase.Checked;
           if (IsChecked)
           {
               if (ValidateMandatoryFields())
               {
                   txtDatabaseName.Text = string.Empty;
                   txtDatabaseName.SendToBack();
                   cbDatabaseName.BringToFront();
                   cbDatabaseName.DataSource = GetDatabaseNames(txtUserName.Text, txtPassword.Text, txtServerName.Text);
               }
               else
               {
                   cbUseExistingDatabase.CheckState = CheckState.Unchecked;
               }

           }
Posted
Updated 25-Aug-14 18:47pm
v2

1 solution

You are almost there. You already calculated IsChecked. Let me rename it according to Microsoft-recommended naming conventions: isChecked.

In the same method, it could be something like
C#
myTextBox.Enabled = !isChecked;
// or
myTextBox.ReadOnly = isChecked;

—SA
 
Share this answer
 
Comments
Anshumaan Chaturvedi 25-Aug-14 13:48pm    
So this will still allow the user to select from the ComboBox? I am asking coz i can test it only when i create the installer which takes a painful 45 minutes
Sergey Alexandrovich Kryukov 25-Aug-14 14:23pm    
No. Any users click won't have effect. I think this is what you were looking for.
—SA
Anshumaan Chaturvedi 25-Aug-14 14:01pm    
thanks... i got the clear picture.
Sergey Alexandrovich Kryukov 25-Aug-14 14:23pm    
You are very welcome.
Good luck, call again.
—SA
Anshumaan Chaturvedi 25-Aug-14 14:26pm    
No,sir.. thing is that user should be able to select the existing database name from the dropdownlist but shouldnot be able to edit it once selected from the list.So, this might work but let me take the call and see. I'll kep you posted. If you can suggest something else also, i would be greatful

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900