Monday, 2 April 2007

Winforms datasource runtime change

ScottSimply put, i wanted to change the datasource of a binding source at runtime. The design behind this is a tab control where all tabs share a common control, therefore the common control needs to be context sensitive to the selected tab so as to display the correct data. Simple enough!!! So why does the code below through generic event handler exceptions???

_MyBindingSource.Clear() // Clears the binding source.
_MyBindingSource.DataSource = CurrentTabContextSensitiveData.
_MyBindingSource.RefreshBindings() // Common control to refresh the bound data.

OR

_MyBindingSource.DataSource = null;
_MyBindingSource.DataSource = CurrentTabContextSensitiveData.
_MyBindingSource.RefreshBindings() // Common control to refresh the bound data.

I dont know why these code samples cause generic exceptions!!

The code that does actually work is;
_MyBindingSource = new BindingSource();
_MyBindingSource.DataSource = CurrentTabContextSensitiveData.
_MyBindingSource.RefreshBindings() // Common control to refresh the bound data.

I hate it when a solutions is found but cant be fully explained or understood. Any ideas out there????

1 comment:

Adi said...

Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.