Repository: beeware/toga

Issue:
Table.data = data is inserting data above old data
## Expected Behavior
I'm trying to replace the data in a Table object to refresh it with live data. 
table = toga.Table(headers['1', '2'], data=[['a', 'b'], ['c', 'd']])

I'd expect the table to only reflect the new data passed in,
table.data = [['e', 'f']]
should be reflected as:
  1  2
  e  f 

## Current Behavior
Currently when I run table.data = [['e', 'f']], it inserts the new data at the top, but does not delete the old data. It makes it look like:
 1 2
 e f
 a b
 c d

## Steps to reproduce
See above

## Your Environment
<!--- Provide details on your current environment you found the bug in -->

* Python Version (list the specific version number)
Python 3.7.6
* Operating System and Version (select from the following and list the specific version number; if your OS is not listed, list that as well)

  - [ ] macOS - version:
  - [ ] Linux - distro:   - version:
  - [x] Windows - version:10
  - [ ] Other - name:  - version:

* Toga Version (list the specific version number or git hash)
'0.3.0.dev18'

* Toga Target (the type of app you are trying to generate)

  - [ ] android
  - [ ] cocoa
  - [ ] django
  - [ ] gtk
  - [ ] iOS
  - [ ] tvOS
  - [ ] watchOS
  - [ ] winforms
  - [x] win32
  - [ ] Other (please specify)



Discussion:
@danshorstein Thanks for the report! That definitely looks like a bug, and it looks like it's Windows specific. The problem is that the `change_source()` method on the winforms backend (the method that is invoked when the data source for the widget changes) *doesn't* call `clear()`. I'll add a fix.

Resolving patch:
diff --git a/examples/table/table/app.py b/examples/table/table/app.py
--- a/examples/table/table/app.py
+++ b/examples/table/table/app.py
@@ -35,6 +35,9 @@ def delete_handler(self, widget, **kwargs):
     def clear_handler(self, widget, **kwargs):
         self.table1.data.clear()
 
+    def reset_handler(self, widget, **kwargs):
+        self.table1.data = bee_movies[3:]
+
     def startup(self):
         self.main_window = toga.MainWindow(title=self.name)
 
@@ -66,7 +69,11 @@ def startup(self):
         btn_insert = toga.Button('Insert Row', on_press=self.insert_handler, style=btn_style)
         btn_delete = toga.Button('Delete Row', on_press=self.delete_handler, style=btn_style)
         btn_clear = toga.Button('Clear Table', on_press=self.clear_handler, style=btn_style)
-        btn_box = toga.Box(children=[btn_insert, btn_delete, btn_clear], style=Pack(direction=ROW))
+        btn_reset = toga.Button('Reset Table', on_press=self.reset_handler, style=btn_style)
+        btn_box = toga.Box(
+            children=[btn_insert, btn_delete, btn_clear, btn_reset],
+            style=Pack(direction=ROW)
+        )
 
         # Most outer box
         outer_box = toga.Box(
diff --git a/src/winforms/toga_winforms/widgets/table.py b/src/winforms/toga_winforms/widgets/table.py
--- a/src/winforms/toga_winforms/widgets/table.py
+++ b/src/winforms/toga_winforms/widgets/table.py
@@ -22,6 +22,7 @@ def create(self):
         self.native.Columns.AddRange(dataColumn)
 
     def change_source(self, source):
+        self.native.Items.Clear()
         for index, row in enumerate(self.interface.data):
             row._impl = WinForms.ListViewItem([
                 getattr(row, attr) for attr in self.interface._accessors


Test patch: