Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to get a listbox depending on both the calendar and a combobox VIDEO

$
0
0

I have filmed my problem as it is easier to explain on video. I want the listbox to display the time began from the bookings table, that relies on the date from the bookings table and the room from the rooms table, is that possible.

Here is a link to the video: Video

Here is the generated XAML:

<CollectionViewSource x:Key="bookingsViewSource" d:DesignSource="{d:DesignInstance {x:Type local:Booking}, CreateList=True}"/><CollectionViewSource x:Key="roomsViewSource" d:DesignSource="{d:DesignInstance {x:Type local:Room}, CreateList=True}"/><CollectionViewSource x:Key="roomsBookingsViewSource" Source="{Binding Bookings, Source={StaticResource roomsViewSource}}"/><CollectionViewSource x:Key="bookingsBookingsViewSource" Source="{Binding Bookings, Source={StaticResource bookingsViewSource}}"/>

This is for the grid:

<Grid x:Name="Grid" SizeChanged="Grid_SizeChanged" Margin="0,0,-0.4,-0.2" DataContext="{StaticResource bookingsViewSource}"     >

This is for the calendar:

 <Calendar x:Name="MainCalendar" Margin="10,135.2,231.8,0" Grid.Row="2" ToolTip="Select a date" DisplayDateStart="2013-01-01" DisplayDateEnd="2020-01-01" FirstDayOfWeek="Monday" Height="177" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" SelectedDatesChanged="datechanged"  SelectedDate="{Binding Date, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" 

This is for the combobox:

<ComboBox x:Name="roomnameComboBox" Grid.Column="1" DisplayMemberPath="Room.Roomname" HorizontalAlignment="Left" Height="27" ItemsSource="{Binding}" Margin="3,5,0,0" Grid.Row="0" VerticalAlignment="Center" Width="120">

And this is for the listbox:

 <ListBox x:Name="listrow" Grid.Column="1" Margin="3.2,1.2,1.8,0" Grid.Row="2" DisplayMemberPath="Timebegan"  SelectionChanged="listrow_SelectionChanged" ItemsSource="{Binding Source={StaticResource bookingsBookingsViewSource}}"/>

Here is the generated C#

 private void Bookings_Loaded(object sender, RoutedEventArgs e)
        {


            WpfApplication7.AllensCroftEntities1 allensCroftEntities1 = new WpfApplication7.AllensCroftEntities1();
            // Load data into Bookings. You can modify this code as needed.
            System.Windows.Data.CollectionViewSource bookingsViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("bookingsViewSource")));
            System.Data.Objects.ObjectQuery<WpfApplication7.Booking> bookingsQuery = this.GetBookingsQuery(allensCroftEntities1);
            bookingsViewSource.Source = bookingsQuery.Execute(System.Data.Objects.MergeOption.AppendOnly);
            // Load data into Rooms. You can modify this code as needed.
            System.Windows.Data.CollectionViewSource roomsViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("roomsViewSource")));
            System.Data.Objects.ObjectQuery<WpfApplication7.Room> roomsQuery = this.GetRoomsQuery(allensCroftEntities1);
            roomsViewSource.Source = roomsQuery.Execute(System.Data.Objects.MergeOption.AppendOnly);
        }

        private void btnFirst_Click(object sender, RoutedEventArgs e)
        {
           listrow.SelectedIndex = 0;
        }

 private System.Data.Objects.ObjectQuery<Booking> GetBookingsQuery(AllensCroftEntities1 allensCroftEntities1)
        {
            System.Data.Objects.ObjectQuery<WpfApplication7.Booking> bookingsQuery = allensCroftEntities1.Bookings;
            // To explicitly load data, you may need to add Include methods like below:
            // bookingsQuery = bookingsQuery.Include("Bookings.Client").
            // For more information, please see http://go.microsoft.com/fwlink/?LinkId=157380
            // Update the query to include Room.Bookings data in Bookings. You can modify this code as needed.
            bookingsQuery = bookingsQuery.Include("Room.Bookings");
            // Returns an ObjectQuery.
            return bookingsQuery;
        }

        private System.Data.Objects.ObjectQuery<Room> GetRoomsQuery(AllensCroftEntities1 allensCroftEntities1)
        {
            System.Data.Objects.ObjectQuery<WpfApplication7.Room> roomsQuery = allensCroftEntities1.Rooms;
            // Update the query to include Bookings data in Rooms. You can modify this code as needed.
            roomsQuery = roomsQuery.Include("Bookings");
            // Returns an ObjectQuery.
            return roomsQuery;
        }


Viewing all articles
Browse latest Browse all 18858

Trending Articles