将组合框选定项与列表项进行比较 [英] Compare Combo box selected item with list items

查看:55
本文介绍了将组合框选定项与列表项进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



  Dim  list  As  列表(  整数
Dim cmd1 作为 SqlCommand( 从SuppReport选择月(FromDate),con)
con.Open()

Dim dr As SqlDataReader = cmd1.ExecuteReader()

while dr.Read()
list.Add(dr( 0 ))
结束

TextBlock12.Text = 字符串 .Join( ,list.ToArray())





i使用此代码,我可以获取此列表中的所有月份数。

现在我必须将每个项目与组合框选择的月份数进行比较,并在数据网格中显示记录。

请告诉我怎么做..

解决方案

你好



你是期待在ComboBox中显示选定的月份编号,但ComboBox不支持多项选择。



让我们从显示月份列表开始:



 <   ListBox     SelectionMode   = 多个    DataContext   =  1,3,5   >  
< ListBox.Items >
< ListBoxItem IsSelected = {Binding
Mode = OneWay,
Converter = {StaticResource csvc},ConverterParameter = 1}
> 1月< / ListBoxItem >
< ListBoxItem IsSelected = {Binding
Mode = OneWay,
Converter = {StaticResource csvc},ConverterParameter = 2} > ; 二月< / ListBoxItem >
< ListBoxItem IsSelected = {Binding
Mode = OneWay,
Converter = {StaticResource csvc},ConverterParameter = 3}
> March < / ListBoxItem >
< ListBoxItem IsSelected = {Binding
Mode = OneWay,
Converter = {StaticResource csvc},ConverterParameter = 4}
> 四月< / ListBoxItem >
< < span class =code-leadattribute> ListBoxItem IsSelected = {Binding
Mode = OneWay,
Converter = {StaticResource csvc},ConverterParameter = 5}
< span class =code-keyword>> 可以< / ListBoxItem >
< / ListBox.Items >
< / ListBox >





csvc是一个转换你的csv的转换器(在这种情况下为1,3,5)并且如果参数在其中则返回true,它的源代码如下



 [ValueConversion ( typeof  string ), typeof  bool ))] 
public class CsvContainsConverter:IValueConverter
{
public object 转换( object value ,输入targetType, object 参数,System.Globalization .CultureInfo文化)
{
return (( string value )。拆分(' ,')。包含(( string < /跨度>)参数);
}

public object ConvertBack( object value ,键入targetType, object 参数,System.Globalization。 CultureInfo culture)
{
throw new NotImplementedException();
}
}





因此,您会看到一个列表视图,显示您选择的月份为IsSelected,那么您需要下载类似DropDown的控件,

你可以使用我的DropDown -

DropDown.cs (控制)

DropDown.xaml (主题)

完整的库



参考控件后,您可以使用下拉列表。

(xmlns :bc =http://www.quickzip.org/BaseControls

xmlns:conv =clr-namespace:QuickZip.Converters; assembly = FileExplorer3)



 <   bc:DropDown  < span class =code-at致敬>   DataContext   =  1, 3,5 >  
< bc:DropDown.Resources >
< < span class =code-leadattribute> conv:CsvContainsConverter x:Key = csvc / >
< / bc:DropDown.Resources >
< bc:DropDown.Header >
< TextBlock 文本 = {Binding} / >
< / bc:DropDown.Header >
< bc:DropDown.Content >
...列表框这里
< / bc:DropDown.Content >
< / bc:DropDown >





结果看起来像这一个:

截图


Hi all

Dim list As New List(Of Integer)
       Dim cmd1 As New SqlCommand("Select Month(FromDate) from SuppReport", con)
       con.Open()

       Dim dr As SqlDataReader = cmd1.ExecuteReader()

       While dr.Read()
           list.Add(dr(0))
       End While

       TextBlock12.Text = String.Join(",", list.ToArray())



i used this code i am able to fetch all the month number in this list.
Now i have to compare each item with combo box selected month number and display the records in a datagrid.
Please tell me how to do this..

解决方案

Hello

Are you looking to show selected month number in a ComboBox, but ComboBox does not support multiple selection.

Lets start from display a list of month :

<ListBox SelectionMode="Multiple" DataContext="1,3,5" >
    <ListBox.Items>
        <ListBoxItem IsSelected="{Binding 
        Mode=OneWay,
        Converter={StaticResource csvc}, ConverterParameter=1}">January</ListBoxItem>
        <ListBoxItem IsSelected="{Binding 
        Mode=OneWay,
        Converter={StaticResource csvc}, ConverterParameter=2}">Febrary</ListBoxItem>
        <ListBoxItem IsSelected="{Binding 
        Mode=OneWay,
        Converter={StaticResource csvc}, ConverterParameter=3}">March</ListBoxItem>
        <ListBoxItem IsSelected="{Binding 
        Mode=OneWay,
        Converter={StaticResource csvc}, ConverterParameter=4}">April</ListBoxItem>
        <ListBoxItem IsSelected="{Binding 
        Mode=OneWay,
        Converter={StaticResource csvc}, ConverterParameter=5}">May</ListBoxItem>
    </ListBox.Items>
</ListBox>



csvc is a Converter that convert your csv (1,3,5 in this case) and return true if Parameter is in it, it's source code like this

[ValueConversion(typeof(string), typeof(bool))]
public class CsvContainsConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return ((string)value).Split(',').Contains((string)parameter);
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}



So you get a list view displaying your selected months as IsSelected, then you need to download a DropDown-like control,
you may use my DropDown -
DropDown.cs (control)
DropDown.xaml (theme)
Full library

After you reference the control, you can use the dropdown.
(xmlns:bc="http://www.quickzip.org/BaseControls"
xmlns:conv="clr-namespace:QuickZip.Converters;assembly=FileExplorer3")

<bc:DropDown DataContext="1,3,5">
  <bc:DropDown.Resources>
    <conv:CsvContainsConverter x:Key="csvc" />
  </bc:DropDown.Resources>
  <bc:DropDown.Header>
    <TextBlock Text="{Binding}" />
  </bc:DropDown.Header>
  <bc:DropDown.Content>
          ...ListBox here
  </bc:DropDown.Content>
</bc:DropDown>



The result is look like this one:
screenshot


这篇关于将组合框选定项与列表项进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆