के साथ एक संग्रह फ़िल्टर करें मैं 6 कॉलम के साथ डेटाग्रिड में अधिकतम 3000 आइटम के साथ एक ऑब्जर्जेबल कोलेक्शन फ़िल्टर करना चाहता हूं। उपयोगकर्ता को "& &" में फ़िल्टर करने में सक्षम होना चाहिए -वे सभी 6 कॉलम।LINQ बनाम संग्रह दृश्य
क्या मुझे इसके लिए LINQ या CollectionView का उपयोग करना चाहिए? LINQ कुछ www नमूनों की कोशिश कर तेजी से लग रहा था। क्या आपके पास कोई समर्थक/विपक्ष है?
अद्यतन:
private ObservableCollection<Material> _materialList;
private ObservableCollection<Material> _materialListInternal;
public MaterialBrowserListViewModel()
{
_materialListInternal = new ObservableCollection<Material>();
for (int i = 0; i < 2222; i++)
{
var mat = new Material()
{
Schoolday = DateTime.Now.Date,
Period = i,
DocumentName = "Excel Sheet" + i,
Keywords = "financial budget report",
SchoolclassCode = "1",
};
_materialListInternal.Add(mat);
var mat1 = new Material()
{
Schoolday = DateTime.Now.Date,
Period = i,
DocumentName = "Word Doc" + i,
Keywords = "Economical staticstics report",
SchoolclassCode = "2",
};
_materialListInternal.Add(mat1);
}
MaterialList = CollectionViewSource.GetDefaultView(MaterialListInternal);
MaterialList.Filter = new Predicate<object>(ContainsInFilter);
}
public bool ContainsInFilter(object item)
{
if (String.IsNullOrEmpty(FilterKeywords))
return true;
Material material = item as Material;
if (DocumentHelper.ContainsCaseInsensitive(material.Keywords,FilterKeywords,StringComparison.CurrentCultureIgnoreCase))
return true;
else
return false;
}
private string _filterKeywords;
public string FilterKeywords
{
get { return _filterKeywords; }
set
{
if (_filterKeywords == value)
return;
_filterKeywords = value;
this.RaisePropertyChanged("FilterKeywords");
MaterialList.Refresh();
}
}
public ICollectionView MaterialList { get; set; }
public ObservableCollection<Material> MaterialListInternal
{
get { return _materialListInternal; }
set
{
_materialListInternal = value;
this.RaisePropertyChanged("MaterialList");
}
}
मैं एक CollectionViewSource फिल्टर इस समय केवल एक कॉलम का उपयोग कर रहा हूँ। क्या आप जानते हैं कि संग्रह केवल तभी अपडेट किया जाता है जब मैंने नीचे की संपत्ति में .efresh() विधि डाली? निजी स्ट्रिंग _filterKeywords सार्वजनिक स्ट्रिंग फ़िल्टरकेड्स { {वापसी _filterKeywords प्राप्त करें; } सेट { अगर (_filterKeywords == मान) वापसी; _filterKeywords = value; यह। रायसप्रॉपर्टी चेंज ("फ़िल्टरकेड्स"); MaterialList.Refresh(); } } – Elisabeth
"क्या आप जानते हैं क्यों ..." - नहीं, लेकिन शायद अगर आप उस कोड को प्रश्न में जोड़ते हैं तो मैं इसे पढ़ सकता हूं। –
ठीक हैनक मैंने सभी महत्वपूर्ण कोड पोस्ट किए! शुभ रात्रि ;-) – Elisabeth