选中复选框时如何禁用编辑选项? [英] How to disable the option of edit when a checkbox is checked?

查看:108
本文介绍了选中复选框时如何禁用编辑选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行sql脚本的Windows应用程序。方案是我已经为用户提供了使用系统中存在的现有数据库的选项。喜欢:



使用现有数据库:(复选框)



如果用户点击它,他将获得系统中存在的数据库下拉列表。但问题是他仍然可以在Dropdownlist \ textBox中编辑。实际上它是一个组合框。

我想在选中复选框时禁用他/她可以编辑的部分。



供参考:



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 :

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;
               }

           }

推荐答案

你几乎就在那里。您已计算 IsChecked 。让我根据Microsoft推荐的命名约定重命名它: isChecked



在同样的方法中,它可以类似

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
myTextBox.Enabled = !isChecked;
// or
myTextBox.ReadOnly = isChecked;



-SA


这篇关于选中复选框时如何禁用编辑选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆