我的用户表单上有一个组合框,应该由vba代码更改,但我不希望任何用户能够键入值,只有vb应具有此功能,用户应该只能选择值。
有什么想法吗?
答案 0 :(得分:2)
答案 1 :(得分:0)
只需将“已锁定”属性更改为True即可。它将阻止用户更改值:但是VBA仍然可以。例如,以下代码锁定ComboBox;然后添加两个值并选择一个:
MySql.Data.MySqlClient.MySqlConnection connection;
string server = "localhost";
string database = "weather";
string uid = "db1";
string password = "db12121";
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" +
database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
try
{
connection.Open();
if (connection.State == ConnectionState.Open)
{
MySqlCommand cmd = new MySqlCommand("insert into forecast (country,city,temperature) values(@Country,@City,@Temperature)", connection);
cmd.Parameters.AddWithValue("@Country", country1);
cmd.Parameters.AddWithValue("@City", city1);
cmd.Parameters.AddWithValue("@Temperature", temperature);
cmd.ExecuteNonQuery();
}
else
{
DisplayMessage.Text = "Database connection failed.";
}
}
catch (Exception ex)
{
}
connection.Close();
}