私はWPF辞書アプリを開発しています。 XAMLコードにリストボックスとテキストボックスがあり、テキストボックスのユーザー入力に基づいてデータセットをフィルタ処理する必要があり、リストボックスには関連する行のみを表示する必要があります。 たとえば、ユーザーがテキストボックスの 't'を入力すると、リストボックスにはテレビのような単語しか表示されません。 問題は、フォームが読み込まれるときにリストボックスが50語で埋められますが、テキストボックス、リストボックスが空白になります。 データセット自体をフィルタリングしようとしましたが、いつもエラーが表示されてしまいましたか?どうやってやるの?wpfでデータセットをフィルタリングする
私のコードはここに
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 System.Data;
using System.Data.OleDb;
using System.ComponentModel;
namespace DictionaryM
{
/// <summary>
/// Interaction logic for Dictionary.xaml
/// </summary>
public partial class Dictionary : Window
{
public ICollectionView view;
public Dictionary()
{
InitializeComponent();
BindData();
}
public void BindData()
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\CellBiology.mdb;Persist Security Info=True");
con.Open();
string sql = "Select Word from Dictionary";
OleDbCommand cmd = new OleDbCommand(sql, con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
da.Fill(ds, "Word");
listBox1.DataContext = ds;
}
catch (Exception ex)
{
label1.Content = ex.Message;
}
private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
{
// i dont know what will i code here?
}
}
thanks everyone who response this question
ご返信ありがとうございます –