Hi all-
I have a basic custom object (class), representing data in a binary file,whose properties are bound to controls on a Windows Form via Drag/Drop databinding. When the app runs, and the user clicks the "Open file" button and selects a file, I first instantiate the object without any data in its properties, then call a method in the object which reads the data intothe object's properties;then, I bind the instance of the object tothe BindingSource control's DataSource propertyin code.
All of the above works fine. But I also have a "Close file" button on the form, whose Code Behindneeds to clear the bound controls on the form, and clear the object. This is so the user can then select another file to load. My problem is, how to clear the BindingSource/object? When I simply set the BindingSource control's DataSourceproperty to Nothing (null), before I can set the object to Nothing, I get an exception: "Cannot bind to the property or column MyPropertyon the DataSource. Parameter name: dataMember", where "MyProperty" is the name of one of the object's properties.
Should I simply Catch the exception and swallow it? That doesn't seem like a good idea. Is there another way to approach this? I don't want to have to manually clear each control's Binding settings every time the user opens a file!
Thanks,
-Andrew