Hi,
I was asked to implement feature to find values in grid (user wants to see all rows so i cant use filters)
user wants (picture)
(1) field to input search text
(2) button to find all rows (kind of bookmark)
(3) button to iterate in find items (find next)
is there built in Search in grid (without filters) ?
I made this feature with this code:
but I am sure there must be better way to do this.
I would appreciate any hint
Thank you
I was asked to implement feature to find values in grid (user wants to see all rows so i cant use filters)
user wants (picture)
(1) field to input search text
(2) button to find all rows (kind of bookmark)
(3) button to iterate in find items (find next)
is there built in Search in grid (without filters) ?
I made this feature with this code:
private void btnFind_Click(object sender, RoutedEventArgs e) { btnFind.IsEnabled = false; scrollIntoFindIndex = 0; string searchText = txtFind.Text; dgDynGrid.SelectedItems.Clear(); foreach (object o in dgDynGrid.Items) { if (o is DataRowView) { for (int z = 0; z < (o as DataRowView).Row.ItemArray.Count(); z++) { try { string t = (o as DataRowView).Row.ItemArray[z].ToString(); if (t.IndexOf(searchText, StringComparison.InvariantCultureIgnoreCase) >= 0) { dgDynGrid.SelectedItems.Add(o); break; } } catch { //if it cant be converted to string, i will not find in this field } } } } btnFind.IsEnabled = true; ScrollIntoFind(0); } int scrollIntoFindIndex = 0; private void ScrollIntoFind(int i) { if (dgDynGrid.SelectedItems.Count > i) { dgDynGrid.ScrollIntoView(dgDynGrid.SelectedItems[i]); } else { scrollIntoFindIndex = 0; MessageBox.Show("Završila je pretraga, idučim klikom se pretražuje od početka", "Kraj pretrage", MessageBoxButton.OK, MessageBoxImage.Information); } } private void btnFindNext_Click(object sender, RoutedEventArgs e) { scrollIntoFindIndex++; ScrollIntoFind(scrollIntoFindIndex); }
but I am sure there must be better way to do this.
I would appreciate any hint
Thank you