Wpf C保存组合框值并在sql中使用以显示分组数据
这是xaml文件中我的组合框的代码:Wpf C保存组合框值并在sql中使用以显示分组数据,wpf,listview,combobox,designer,Wpf,Listview,Combobox,Designer,这是xaml文件中我的组合框的代码: <telerik:RadComboBox Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" telerik:TextSearch.TextPath="Name" Margin="0 0 10 0" IsEditable="True" ItemsSource="{Binding AvailableFunds}"
<telerik:RadComboBox Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" telerik:TextSearch.TextPath="Name" Margin="0 0 10 0"
IsEditable="True" ItemsSource="{Binding AvailableFunds}"
DisplayMemberPath="Perioada"
SelectedValuePath="Perioada"
SelectedValue="{Binding Path=Perioada}"
SelectedIndex="0"
SelectionBoxTemplate="{StaticResource ComboBoxSimpleTemplate}" SelectionChanged="RadComboBox_SelectionChanged"/>
组合框显示一些日期、年份和月份,客户可以在其中选择一个。然后,我需要在列表视图中显示所选期间的所有日期:
<ListView Grid.Row="4" Grid.Column="1" ItemsSource="{Binding SalesGroupedByPartners}" Margin="0,0,10,0" ScrollViewer.HorizontalScrollBarVisibility="Auto">
<ListView.View>
<GridView >
<GridViewColumn Header="Perioada" Width="100" DisplayMemberBinding="{Binding Path=Perioada}"/>
<GridViewColumn Header="Nume Client" Width="300" DisplayMemberBinding="{Binding Path=Client}"/>
<GridViewColumn Width="120" Header="Suma">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Width="120" TextAlignment="Right" Text="{Binding Path=Suma, StringFormat=N2}" Margin="-6,0" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
在.cs文件中,我有一个空方法:
private void RadComboBox_SelectionChangedobject发件人,SelectionChangedEventArgs e
{
}
我试图在此方法中创建一个字符串并保存ComboBox的结果,但无法访问它,因为ComboBox没有名称
或者,我可以直接将选项发送到sql文件….:
声明@Period
在这里设置@Period=client选项我不知道从ComboBox调用
并在ListView中显示:
从表中选择*
其中Period=@Period
我试图在此方法中创建一个字符串并保存ComboBox的结果,但无法访问它,因为ComboBox没有名称
通过在事件处理程序中强制转换sender参数,可以获得对RadComboBox的引用:
private void RadComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Telerik.Windows.Controls.RadComboBox comboBox = sender as Telerik.Windows.Controls.RadComboBox;
object value = comboBox.SelectedValue;
//...
}
但由于绑定到Perioada属性,因此也可以从该属性检索当前选定的值
我试图在此方法中创建一个字符串并保存ComboBox的结果,但无法访问它,因为ComboBox没有名称
通过在事件处理程序中强制转换sender参数,可以获得对RadComboBox的引用:
private void RadComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Telerik.Windows.Controls.RadComboBox comboBox = sender as Telerik.Windows.Controls.RadComboBox;
object value = comboBox.SelectedValue;
//...
}
但由于绑定到Perioada属性,因此也可以从此属性检索当前选定的值。已解决:D
在xaml.cs文件中,需要添加一些代码:
cn.Open();
SqlCommand cmd = new SqlCommand(Properties.Resources.SalesGroupedByPartners, cn);
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = 100;
cmd.Parameters.AddWithValue("@Perioada", Perioada);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(salesGroupedByPartners);
cn.Close();
及
答案:D
在xaml.cs文件中,需要添加一些代码:
cn.Open();
SqlCommand cmd = new SqlCommand(Properties.Resources.SalesGroupedByPartners, cn);
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = 100;
cmd.Parameters.AddWithValue("@Perioada", Perioada);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(salesGroupedByPartners);
cn.Close();
及
我试图在此方法中创建一个字符串并保存ComboBox的结果,但无法访问它,因为ComboBox没有名称。当您像以前一样使用MVVM模式和绑定时,不需要名称;Perioada属性中的值不是吗?Perioada只是.sql文件中显示所有日期的一列。根据此选择,新的.sql查询需要有一行,其中Period=@Period selected Period by client and dt这就是为什么在将数据库对象绑定到视图时这是一种错误的模式。您应该使用viewmodels并绑定其属性。那么从ComboBox或任何其他控件获取值就不会有问题了。我试图用这个方法创建一个字符串并保存ComboBox的结果,但无法访问它,因为我的ComboBox没有名称。当您像以前一样使用MVVM模式和绑定时,不需要名称;Perioada属性中的值不是吗?Perioada只是.sql文件中显示所有日期的一列。根据此选择,新的.sql查询需要有一行,其中Period=@Period selected Period by client and dt这就是为什么在将数据库对象绑定到视图时这是一种错误的模式。您应该使用viewmodels并绑定其属性。那么从ComboBox或任何其他控件获取值就不会有问题。错误1找不到类型或命名空间名称“RadComboBox”是否缺少using指令或程序集引用?真的吗,我需要一个名为我的组合框的名称空间|在代码文件顶部添加以下using语句,或根据我编辑的答案使用完全限定名:using Telerik.Windows.Controls;。错误1找不到类型或命名空间名称“RadComboBox”是否缺少using指令或程序集引用?真的吗,我需要一个名为我的组合框的名称空间|在代码文件顶部添加以下using语句,或根据我编辑的答案使用完全限定名:using Telerik.Windows.Controls;。