对于我的 winforms 程序,我有一个选项对话框,当它关闭时,我循环浏览所有对话框控件名称(文本框、复选框等)及其值并将它们存储在数据库中,以便我可以从中读取我的程序。正如您在下面看到的,我可以轻松地Text
从Control
组中访问属性,但是没有属性可以访问Checked
文本框的值。c
在这种情况下,我是否需要先转换为复选框?
conn.Open();
foreach (Control c in grp_InvOther.Controls)
{
string query = "INSERT INTO tbl_AppOptions (CONTROLNAME, VALUE) VALUES (@control, @value)";
command = new SQLiteCommand(query, conn);
command.Parameters.Add(new SQLiteParameter("control",c.Name.ToString()));
string controlVal = "";
if (c.GetType() == typeof(TextBox))
controlVal = c.Text;
else if (c.GetType() == typeof(CheckBox))
controlVal = c.Checked; ***no such property exists!!***
command.Parameters.Add(new SQLiteParameter("value", controlVal));
command.ExecuteNonQuery();
}
conn.Close();
如果我需要先转换c
,我该怎么做?