我在我的应用程序中使用了 4 个复选框,并创建了一个整数列表以在选中复选框时添加值。该值将使用 sqlite 存储在我的数据库中。这是我的代码:
List<int> hobid = new List<int>();
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (Convert.ToBoolean(cricket.IsChecked))
{
hobid.Add(1);
}
else if (Convert.ToBoolean(football.IsChecked))
{
hobid.Add(2);
}
else if (Convert.ToBoolean(music.IsChecked))
{
hobid.Add(3);
}
else if (Convert.ToBoolean(reading.IsChecked))
{
hobid.Add(4);
}
int rec;
string strInserthob = "Insert into User_hobbies (User_id,Hobbies_id) values (@User_id,@Hobbies_id)";
//Here insertion is done..
for (int i = 0; i < hobid.Count; i++)
{
User_hobbies txt = new User_hobbies
{
User_id = userid,
Hobbies_id = hobid[i]
};
rec = (Application.Current as App).db.Insert<User_hobbies>(txt, strInserthob);
}
}
您能否建议我如何在选中复选框时获取列表中的值。