Hi all,
I'm working on a WPF solution where I have to populate a combobox depending on the selected item of another combobox. But I get an error.
The XAML code is:
<Window xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
x:Class="ICP.Reporting.WPFReportViewer.Windows.Report_Script_Resultaten"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:Infragistics.Silverlight.SampleBrowser.Framework.Controls;assembly=Infragistics.Silverlight.SampleBrowser.Framework"
xmlns:ig="http://schemas.infragistics.com/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:uri="clr-namespace:ICP.Reporting.WPFReportViewer.Resources.ReportUri"
xmlns:res="clr-namespace:ICP.Reporting.WPFReportViewer.Resources.Pages"
d:DesignHeight="500" d:DesignWidth="567" SizeToContent="WidthAndHeight"
Title="Report Scripts Resultaten"
WindowStartupLocation="CenterScreen" Icon="/ICP.Reporting.WPFReportViewer;component/Images/Report_New.ico">
<Window.Resources>
<uri:ReportLibraryUri x:Key="ReportLibraryUri" />
<res:ParametersStrings x:Key="ParametersStrings" />
</Window.Resources>
<Grid x:Name="LayoutRoot" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Name="stackPanelParameters" Orientation="Vertical" VerticalAlignment="Top" Height="Auto" HorizontalAlignment="Center" Width="170" Grid.Row="0"
Grid.RowSpan="1" Grid.Column="0" Grid.ColumnSpan="1" Margin="10,5">
<GroupBox Name="groupBoxBeginEindDatum" Header="Kies begin- en einddatum" Height="Auto" Width="Auto" Margin="0,5,0,0" HorizontalContentAlignment="Center"
VerticalContentAlignment="Center">
<StackPanel Name="stackPanelBeginEindDatum" Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center"
Height="Auto" Width="Auto" >
<!-- <Label Height="28" Content="{Binding Source={StaticResource ParametersStrings}, Path=Binding_StartDate}" Margin="15,10,5,10"
Width="77"/> -->
<Label Height="20" Content="Begindatum:" Margin="15,5,15,0" Width="77" Padding="5,0" HorizontalAlignment="Center"
HorizontalContentAlignment="Center" />
<!--<DatePicker Name="datePickerBeginDatum" Height="23" Width="120" SelectedDateFormat="Short" DisplayDate="{x:Static
sys:DateTime.Now}" Text="" SelectedDate="{x:Static sys:DateTime.Now}" Margin="5,0" Padding="2" />-->
<DatePicker Name="datePickerBeginDatum" Height="23" Width="120" SelectedDateFormat="Short" DisplayDate="01-01-2012"
Text="" SelectedDate="01-01-2012" Margin="5,0" Padding="2" />
<!-- <Label Height="28" Content="{Binding Source={StaticResource ParametersStrings}, Path=Binding_EndDate}" Margin="15,10,5,10"
Width="70"/> -->
<Label Height="20" Content="Einddatum:" Margin="15,5,15,0" Width="77" Padding="5,0" HorizontalAlignment="Center"
HorizontalContentAlignment="Center" />
<!--<DatePicker Name="datePickerEindDatum" Height="23" Width="120" SelectedDateFormat="Short" DisplayDate="{x:Static
sys:DateTime.Now}" Text="" SelectedDate="{x:Static sys:DateTime.Now}" Margin="5,0" Padding="2" />-->
<DatePicker Name="datePickerEindDatum" Height="23" Width="120" SelectedDateFormat="Short" DisplayDate="12-31-2012"
Text="" SelectedDate="12-31-2012" Margin="5,0" Padding="2" />
</StackPanel>
</GroupBox>
<GroupBox Name="groupBoxAuthoriteitScript" Header="En authoriteit en script" Height="Auto" Width="Auto" Margin="0,5,0,0" HorizontalContentAlignment="Center"
VerticalContentAlignment="Center">
<StackPanel Name="stackPanelAuthoriteitScript" Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center"
Height="Auto" Width="Auto">
<Label Height="20" Content="Authoriteit:" Margin="15,5,15,0" Width="77" Padding="5,0" HorizontalAlignment="Center"
HorizontalContentAlignment="Center" />
<ComboBox Height="25" Name="comboBoxAuthoriteit" Margin="5,0" Padding="2" SelectedIndex="-1"
ItemsSource="{Binding}" DisplayMemberPath="Name" IsSynchronizedWithCurrentItem="True" SelectionChanged="comboBoxAuthoriteit_SelectionChanged" />
<Label Height="20" Content="Script:" Margin="15,5,15,0" Width="77" Padding="5,0" HorizontalAlignment="Center"
HorizontalContentAlignment="Center" />
<ComboBox Height="25" Name="comboBoxScript" Margin="5,0" Padding="2" SelectedIndex="-1" ItemsSource="{Binding}"
DisplayMemberPath="Name" />
</StackPanel>
</GroupBox>
<GroupBox Name="groupBoxRapport" Header="Rapport" Height="Auto" Width="Auto" Margin="0,5,0,0" HorizontalContentAlignment="Center"
VerticalContentAlignment="Center">
<StackPanel Name="stackPanelRapport" Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center" Height="Auto"
Width="Auto">
<!-- <Button Content="{Binding Source={StaticResource ParametersStrings}, Path=Refresh}" Margin="20,5,10,5" Click="Button_Refresh_Click"
Height="23" Width="61" /> -->
<Button Content="Genereer rapport" Margin="5" Click="Button_Refresh_Click" Height="23" Width="100"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</StackPanel>
</GroupBox>
</StackPanel>
<ig:XamReportViewer HorizontalAlignment="Center" Name="xamReportViewer1" VerticalAlignment="Bottom" PageFit="Width" UseLayoutRounding="True" MinWidth="380"
MinHeight="445" PageMargin="0" AutoRender="True" Grid.Row="0" Grid.Column="1" Margin="0">
<ig:XamReportViewer.RenderSettings>
<ig:ClientRenderSettings DefinitionUri="/ICP.Reporting.ReportingClassLibrary;component/ReportDesigns/Report_Scripts_Resultaten.igr" />
</ig:XamReportViewer.RenderSettings>
<!-- Binding parameters -->
<ig:XamReportViewer.Parameters>
<ig:Parameter ParameterName="beginDatum" ParameterValue="{Binding ElementName=datePickerBeginDatum, Path=SelectedDate}"/>
<ig:Parameter ParameterName="eindDatum" ParameterValue="{Binding ElementName=datePickerEindDatum, Path=SelectedDate}"/>
<!--<ig:Parameter ParameterName="Maand" ParameterValue="{Binding ElementName=comboBoxMaand, Path=SelectedValue}"/>
<ig:Parameter ParameterName="Jaar" ParameterValue="{Binding ElementName=comboBoxJaar, Path=SelectedValue}"/>
<ig:Parameter ParameterName="Authoriteit" ParameterValue="{Binding ElementName=comboBoxAuthoriteit, Path=SelectedItem}"/>
<ig:Parameter ParameterName="Script" ParameterValue="{Binding ElementName=comboBoxScript, Path=SelectedItem}"/>-->
</ig:XamReportViewer.Parameters>
</ig:XamReportViewer>
</Grid>
</Window>
The code behind is:
using ICP.Reporting.ReportingClassLibrary;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Infragistics.Controls.Reports;
namespace ICP.Reporting.WPFReportViewer.Windows
{
/// <summary>
/// Interaction logic for Report_Script_Resultaten.xaml
/// </summary>
public partial class Report_Script_Resultaten : Window
{
public Report_Script_Resultaten()
{
InitializeComponent();
CultureInfo ci = CultureInfo.CreateSpecificCulture(CultureInfo.CurrentCulture.Name);
ci.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
ci.DateTimeFormat.DateSeparator = "-";
Thread.CurrentThread.CurrentCulture = ci;
//datePickerBeginDatum.DisplayDate = DateTime.Today.AddDays(-7);
//datePickerBeginDatum.SelectedDate = DateTime.Today.AddDays(-7);
//datePickerEindDatum.DisplayDate = DateTime.Today.AddDays(-1);
//datePickerEindDatum.SelectedDate = DateTime.Today.AddDays(-1);
BindComboBoxAuthoriteit(comboBoxAuthoriteit);
}
private void Button_Refresh_Click(object sender, RoutedEventArgs e)
{
this.xamReportViewer1.Refresh();
}
public void BindComboBoxAuthoriteit(ComboBox comboBoxName)
{
string strConnectionAuthoriteit = ConfigurationManager.ConnectionStrings["ICP.Reporting.ReportingClassLibrary.Properties.Settings.sqlDS_Authorities"].ConnectionString;
SqlConnection connectionAuthoriteit = new SqlConnection(strConnectionAuthoriteit);
SqlDataAdapter daAuthoriteit = new SqlDataAdapter("SELECT Authority_ID, Description FROM Authorities ORDER BY Description", connectionAuthoriteit);
DataSet dsAuthoriteit = new DataSet();
daAuthoriteit.Fill(dsAuthoriteit, "Authorities");
comboBoxName.ItemsSource = dsAuthoriteit.Tables[0].DefaultView;
comboBoxName.DisplayMemberPath = dsAuthoriteit.Tables[0].Columns["Description"].ToString();
comboBoxName.SelectedValuePath = dsAuthoriteit.Tables[0].Columns["Authority_ID"].ToString();
}
private void comboBoxAuthoriteit_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (comboBoxAuthoriteit.SelectedIndex > -1)
{
BindComboBoxScript(comboBoxScript);
}
}
public void BindComboBoxScript(ComboBox comboBoxName)
{
string strqryScript = string.Format("SELECT Questionnaire_Id, Questionnaire_Name FROM Questionnaires WHERE (Authority_ID = {0}) ORDER BY Questionnaire_Name", comboBoxAuthoriteit.SelectedItem);
string strConnectionScript = ConfigurationManager.ConnectionStrings["ICP.Reporting.ReportingClassLibrary.Properties.Settings.sqlDS_Scripts"].ConnectionString;
SqlConnection connectionScript = new SqlConnection(strConnectionScript);
SqlDataAdapter daScript = new SqlDataAdapter(strqryScript, connectionScript);
DataSet dsScript = new DataSet();
//DataTable dtScript = new DataTable();
daScript.Fill(dsScript, "Questionnaires");
comboBoxName.ItemsSource = dsScript.Tables[0].DefaultView;
comboBoxName.DisplayMemberPath = dsScript.Tables[0].Columns["Questionnaire_Name"].ToString();
comboBoxName.SelectedValuePath = dsScript.Tables[0].Columns["Questionnaire_Id"].ToString();
//foreach (DataRow drScript in dsScript.Tables)
//{
//comboBoxScript.Items.Add(drScript[0].ToString());
//}
}
}
}
When I run the solution I get the sqlexception "The multi-part identifier "System.Data.DataRowView" could not be bound."
on the following line:
daScript.Fill(dsScript, "Questionnaires");
Can someone tell me where I'm going wrong and what I have to correct?
Thank you very much for your help.
Greetings,
Geert De Vylder