對於我的winforms程序,我有一個選項對話框,當它關閉時,我循環顯示所有對話框控件名稱(文本框,複選框等)及其對象值並將它們存儲在數據庫中,以便我可以在程序中讀取它。如下所示,我可以輕鬆地訪問Control
組中的Text
屬性,但沒有屬性可以訪問文本框的Checked
值。在那種情況下,我需要先將c
轉換爲複選框嗎?以編程方式通過winform控件獲取checkbox.checked值從循環到winform控件
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
,我該怎麼做呢?
是的,你必須轉換。 –