各位大家好,我正在做一个项目,我在列表视图中列出了保存在文本文件中的项目,但现在我有一个问题我想把一个组合框放在哪里我可以选择两个选项和过滤列表视图。我怎样才能做到这一点?我有一个过滤器,但不能正常工作每次我从组合框中选择两个项目中的一个他告诉我另一个在listView中有像切换。这是我的代码谢谢: private readonly ObservableCollection< Chave> chaves = new ObservableCollection< Chave>(); public ConsultarChaves() { InitializeComponent(); } private void button_voltar_Click(object sender,RoutedEventArgs e) { MainWindow sw = new MainWindow(); sw.Show(); this.Close(); } private void button_consultar_chaves_Click(object sender,RoutedEventArgs e) { string [] lines = File.ReadAllLines(GerarChave.FilePath); foreach(行中的换行符) { string [] parts = line.Split(','); Chave a = new Chave(); a.numero1 = parts [0]; a.numero2 = parts [1]; a.numero3 =部分[2]; a.numero4 = parts [3]; a.numero5 = parts [4]; a.estrela1 =部分[5]; a.estrela2 =部分[6]; a.DiaDaSemana =部分[7]; a.Data = parts [8]; chaves.Add(a); }¥b $ b listView.ItemsSource = chaves; } private bool myTextFilter(object item) { if(String.IsNullOrEmpty(comboBox_filtro.Text)) 返回true; var chaves =(Chave)item; return(chaves.DiaDaSemana.StartsWith(comboBox_filtro.Text)); $ } private void comboBox_filtro_SelectionChanged(object sender,SelectionChangedEventArgs e) { $ ICollectionView view = CollectionViewSource.GetDefaultView(listView.ItemsSource); view.Filter = myTextFilter; }¥b $ b }
Hello everyone, i'm doing a project where i list items in a listview that are saved in a text file, but now i have a problem i want to put a combobox where i can select between two option and filter the listview. How can i do this? i have do a filter but is not working properly every time i select one of the two items from the combobox he show me the other one in the listView there are like switched. Here is my code thanks: private readonly ObservableCollection<Chave> chaves = new ObservableCollection<Chave>(); public ConsultarChaves() { InitializeComponent(); } private void button_voltar_Click(object sender, RoutedEventArgs e) { MainWindow sw = new MainWindow(); sw.Show(); this.Close(); } private void button_consultar_chaves_Click(object sender, RoutedEventArgs e) { string[] lines = File.ReadAllLines(GerarChave.FilePath); foreach(string line in lines) { string[] parts = line.Split(','); Chave a = new Chave(); a.numero1 = parts[0]; a.numero2 = parts[1]; a.numero3 = parts[2]; a.numero4 = parts[3]; a.numero5 = parts[4]; a.estrela1 = parts[5]; a.estrela2 = parts[6]; a.DiaDaSemana = parts[7]; a.Data = parts[8]; chaves.Add(a); } listView.ItemsSource = chaves; } private bool myTextFilter(object item) { if (String.IsNullOrEmpty(comboBox_filtro.Text)) return true; var chaves = (Chave)item; return (chaves.DiaDaSemana.StartsWith(comboBox_filtro.Text)); } private void comboBox_filtro_SelectionChanged(object sender, SelectionChangedEventArgs e) { ICollectionView view = CollectionViewSource.GetDefaultView(listView.ItemsSource); view.Filter = myTextFilter; } }
-------------------------------------
-------------------------------------
XAML代码
推荐答案
您好,
欢迎来到MSDN论坛。
Welcome to MSDN forum.
这个论坛是关于visual studio IDE的,我将把你的主题转移到WPF论坛寻求专业支持,谢谢理解。
This forum is to talk about visual studio IDE, I will move your thread to WPF forum for professional support, thank you for understanding.
祝你好运,
Joyce
更多推荐
C#WPF ComboBox过滤ListView
发布评论