BindinSource.Filterで検索する方法を知りたいです。私はこのようなコードを持っていますSuche.Filter = string.Format("{0} = '{1}'", "ID", ergebnis);
ergebnisは私の連絡先のすべてのIDを持つ私の配列です。今私は、これは私がそれを解決する方法ですDGVC#Dataの値を配列の値でフィルタリングする
1
A
答えて
0
で同じIDを持つすべての連絡先を表示したい:私は単に新しいDataTable
にDataGridView
の内容をコピー
private void filter(int selectedID) {
DataTable dtFilter = new DataTable();
//speichere GridView zum Filtern
dtFilter = (DataTable)this.grdMDT.DataSource;
try {
dtFilter = dtFilter.Select("ID = " + selectedID).CopyToDataTable();
this.DGV.DataSource = dtFilter;
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
とSelect
を使用して、必要なすべての結果を得ることができます。 GridView
に新しいDataSource
を設定しました。
GridView
の元の内容を別のDataTable
に保存して、フィルタの結果をクリアしたい場合があります。
もちろん、for-loopの外側でこれを行う必要があります。
0
あなたは、フィルタロジックに
private bool FilterPerItem(Contact item)
{
int rightID = 1;
if (item.ID == rightID)
{
return true;
}
else return false;
}
0
を追加するオブジェクトFilterPerItem
で
ICollectionView view = CollectionViewSource.GetDefaultView(yourdatagridview);
view.Filter = FilterPerItem;
yourdatagridview.ItemsSource = view;
の配列をビューを取得し、あなたの配列を作ることによって、フィルタを適用することができ、私は、私のコードのために結果を見つけましたみんなありがとう!
try
{
int[] ergebnis = new int[20];
var filterString = new List<string>();
for (int i = 1; i < result.Length; i++)
{
int j = Int32.Parse(result[i][12]);
ergebnis[i] = j;
filterString.Add(string.Format("{0} = '{1}'", "ID", j));
}
Suche.Filter = string.Join(" OR ", filterString);
kitba();
}
catch (IndexOutOfRangeException ex)
{
Debug.WriteLine(ex);
}