How does WPF filter the DataGrid associated with a DataTable in WPF?
3 answers
In order to filter the datagrid, you need to create a string and build it
Grid myParent; string strFilterResult; string strFilter; string str; string dType=myParent.dataSetOffice.Tables[myParent.strTable]. Columns[i].DataType.FullName.ToString().Remove(0,7); And then you need to check, for example:
if (textBox1.Text != "" && dType=="Int32") { str += " and " + "id" + "=" + textBox1.Text; } if (textBox2.Text != "" && dType == "String") { str += " and " + "string" +" like'%"+textBox2.Text+"%'"; } strFilter = str.Substring(0, 4); strFilterResult = strFilter; if (strFilterResult == " and") { strFilterResult = str.Remove(0, 4); } And this is all I hung on the button.
|
Thanks for the answer! Waiting for him, I made myself through
{ BindingListCollectionView tarelkiViewSource = (BindingListCollectionView)CollectionViewSource.GetDefaultView(tarelkiTableAdapter.GetData()); // создание представления данных ADO.NET if(tarelkiViewSource!=null) { tarelkiViewSource.CustomFilter="tmin=4";//фильтрация данных } grid.DataContext = tarelkiViewSource;//привязка данных к сетке окна } |
You can even XML for a specific field for example
<dxg:GridColumn Header="Time Data" FieldName="TimeData" SortMode="DisplayText" SortOrder="Ascending"/> |