我在折叠网格后选中复选框项目,然后再次单击以查看网格

本文关键字:网格 然后 单击 项目 折叠 复选框 | 更新日期: 2023-09-27 18:28:00

我正在事件处理程序中从数据库获取ID。

private void buttonAddRooms_Click(object sender, RoutedEventArgs e) {
        EditRoomsDataGrid.Visibility = Visibility.Collapsed;
        AddRoomsDataGrid.Visibility = Visibility.Visible;
        Room room = new Room();
        RoomFactory fac = new RoomFactory();
        room.Room_ID = fac.RoomID();
        txtRoomID.Text = room.Room_ID.ToString();
        //COBbadspace.SelectedItem = -1;
 }

as button saved在插入数据库后单击表单中的所有值,但当我再次单击addroombutton以显示网格时,所有最后选中的项目都显示为已选中,所以我希望有一种方法,当我单击addroomb button以显示格线时,所有复选框都未选中,文本框都清除/为空,因为当我再次点击以显示网格,所有值都仍然存在。clbfacities是一个包含组合项的检查表框。

private void btnSaveRoom_Click(object sender, RoutedEventArgs e) {
        Room room = new Room();
        RoomFactory fac=new RoomFactory();
        room.RoomType = COBbadspace.SelectionBoxItem.ToString();
       // room.RoomType = txtbadsapace.Text;
        foreach (var item in clbFacilities.SelectedItems)
        {
            room.RoomFacilities += (item as ComboBoxItem).Content + ",";
        }
        String price = txtRoomPrice.Text;
        room.Room_Price = Convert.ToInt32(price);
        if (rbAvailable.IsChecked ?? false)
            room.Room_Status = true;
        else
            room.Room_Status = false;
        if (fac.Insert(room))
         {
            MessageBox.Show("insert");
         }
        else
            MessageBox.Show("not insert");
        AddRoomsDataGrid.Visibility = Visibility.Collapsed;
        EditRoomsDataGrid.Visibility = Visibility.Collapsed;
        viewRoomsGrid.Visibility = Visibility.Visible;

}

我在折叠网格后选中复选框项目,然后再次单击以查看网格

编写一个函数,清除所有复选框和texboxex

private void CleanRoomGui()
{
chBx1.isChecked = false;
chBx2.isChecked = false;
txtRoomID.Text = String.Empty;
txtRoomName.Text = String.Empty;
}

这是我的答案,因为我不知道你的设计是什么样子的。

如果你有一个带有复选框和文本框的窗口,你可以加载这个新窗口,当你这样做时,默认值将被使用。

private void GetRoomDetails()
{
    var roomDetails = new Details();
    if(roomDetails.ShowDialog() = DialogResult.OK)
    {            
        txtRoomID.Text = roomDetails.Room_ID.ToString();
    } 
}
相关文章: