0

I have made a delete/clear button that works, but after using it I cannot make a new search...I also have a refresh button that doesn't work at all. I want to be able to make a ned search and I thought I could use the refresh button for this.

Can you help me? If you can, please explain it for me with an example.

private void Button_Click(object sender, RoutedEventArgs e)
{
    dataGridTest.ItemsSource = null; 
}

private void Refresh_Click(object sender, RoutedEventArgs e)
{
    dataGridTest.Items.Refresh();
}
dkozl
  • 32,814
  • 8
  • 87
  • 89
user3416819
  • 37
  • 1
  • 5
  • 1
    if you bind to [`ObservableCollection`](http://msdn.microsoft.com/en-us/library/ms668604(v=vs.110).aspx) then you won't have to worry about refresh – dkozl Mar 19 '14 at 22:03
  • Sorry, I don't get it. What do you mean by " I want to be able to make a ned search and I thought I could use the refresh button for this."? – terry Mar 19 '14 at 22:04
  • You should not reset the ItemsSource for clearing the list. Bind to a ObservableCollection and Clear the collection instead. Refresh is not needed at all if the binding is made properly. – BlueM Mar 19 '14 at 22:06
  • Moreover, you shouldn't need to call methods or change properties of the UI element at all. The bindings should do all the work for you if you do it right. – BradleyDotNET Mar 19 '14 at 22:24
  • Instead of editing someone else's answer with your code, edit your own question. – Uyghur Lives Matter Mar 22 '14 at 15:42
  • I tried to add a comment, but it was too many characters...But if you can see it, then maby you could help insted of telling me whats wrong with my posting? :) Can't edit my own right now. Will do it as soon as i get a chance ;) Thanks anyway! – user3416819 Mar 22 '14 at 16:22
  • How you did the first search? At the very least, the reset button should call that again. I agree with the above, that adding an `ObservableCollection` with the results plus a `Binding` will help you in adding the results visually. – Alejandro Mar 22 '14 at 16:57

1 Answers1

0

There's some part of your code that we need to see so that we can able to help. But if you are working with WPF, WPF is awesome with MVVM Design pattern.

You can check some start up here.

Josh Smith's tutorial is the best tutorial about MVVM.

Community
  • 1
  • 1
jomsk1e
  • 3,585
  • 7
  • 34
  • 59
  • MVVM is not specific to WPF. And given that the OP *seems* to be new to WPF, it might be a bit overwhelm to introduce it yet. – Alejandro Mar 22 '14 at 16:55