For my winforms program, I have an Options dialog box, and when it closes, I cycle throught all the Dialog Box control names (textboxes, checkboxes, etc.) and their values and store them in a database so I can read from it in my program. As you can see below, I can easily access the Text
property from the Control
group, but there's no property to access the Checked
value of the textbox. Do I need to convert c
, in that instance, to a checkbox first?
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();
If I need to convert c
first, how do I go about doing that?