c# - Get checkbox.checked value programmatically from cycling through winform controls -
for winforms program, have options dialog box, , when closes, cycle throught dialog box control names (textboxes, checkboxes, etc.) , values , store them in database can read in program. can see below, can access text
property control
group, there's no property access checked
value of textbox. need convert c
, in instance, checkbox first?
conn.open(); foreach (control c in grp_invother.controls) { string query = "insert 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 need convert c
first, how go doing that?
yes, need convert it:
else if (c.gettype() == typeof(checkbox)) controlval = ((checkbox)c).checked.tostring();
and can make check simpler read:
else if (c checkbox) controlval = ((checkbox)c).checked.tostring();
Comments
Post a Comment