A WPF Navigation application using C# -
Page1.xaml has a DataGrid (DataGrid1) defined like this:
<DataGrid x:Name="DataGrid1" AlternatingRowBackground="LightBlue" HorizontalAlignment="Left" Margin="10,118,0,0" VerticalAlignment="Top" Height="437" Width="764" Background="{x:Null}" ><DataGrid.Columns><DataGridTemplateColumn IsReadOnly="True"/><DataGridTextColumn Header="Record #" Width="70" Binding="{Binding RecordID}"/><DataGridTextColumn Header="Group Name" Width="180" Binding="{Binding GroupName}"/><DataGridTextColumn Header="Group Notes" Width="180" Binding="{Binding GroupNotes}"/><DataGridTextColumn Header="Arrive Date" Width="100" Binding="{Binding VisitDate, StringFormat=yyyy-MM-dd}" /><DataGridTextColumn Header="Arrive Time" Width="100" Binding="{Binding ArrivalTime}"/><DataGridTextColumn Header="Quantity" Width="70" Binding="{Binding GroupTotal}"/><DataGridTextColumn Header="Shed" Width="70" Binding="{Binding ShedAssignment}"/><DataGridTextColumn Header="Rows" Width="70" Binding="{Binding ShedRow}"/><DataGridCheckBoxColumn Header="Catered" Width="60" Binding="{Binding Catered}"/></DataGrid.Columns></DataGrid>
Using two DatePickers to select a range of dates the program executes the following method when a Search button is clicked:
private void Search_Click(object sender, RoutedEventArgs e) { searchreservations = new SqlCommand("SELECT RecordID, GroupName, GroupNotes, VisitDate, ArrivalTime, (StudentCount + AdultCount + ChaperoneCount + ChildCount + SeniorCount) as GroupTotal, ShedAssignment, ShedRow, Catered" +" FROM tblGroups WHERE VisitDate >='" + StartDate.Text + "' AND VisitDate <= '" + EndDate.Text + "'", connection); OpenConnection(); SqlDataAdapter grpview = new SqlDataAdapter(searchreservations); DataTable grp = new DataTable("GroupView"); grpview.Fill(grp); DataGrid1.ItemsSource = grp.DefaultView; CloseConnection(); }
The method seems to be working since data is returned and placed in the grid. The problem is this is being done twice in the same row. Each row contains 18 columns. The first 9 are formatted as defined in Page1.xaml and the last nine are from the Datagrid1.ItemSource = grp.DefaultView; statement.
Here is the question - How do I get the DataTable to fill in DataGrid1 as formatted in Page1.xaml and not add the additional 9 "DefaultView" columns?