Question BindingSource does not refreshed

ekekakos

New member
Joined
Feb 8, 2009
Messages
2
Programming Experience
1-3
When a form is loaded I get the data to a dataset and then I bind it to a BindingSource, which finally is being binded to a Listbox
VB.NET:
'Bind all the bindings
        BindingSourceRestrictedMenus.DataSource = DatasetRestrictedMenus
        BindingSourceRestrictedMenus.DataMember = "SecurityRestrictions"

        'Bind the listbox to the Restricted Menus
        ListBoxControlMenus.DataSource = BindingSourceRestrictedMenus
        ListBoxControlMenus.DisplayMember = "FullName"
        ListBoxControlMenus.ValueMember = "ID"

I have a button refreshed which gets again the new dataset data but the bindingsource continues to have the old records. The code is:
VB.NET:
DatasetRestrictedMenus = oAdministrationProcess.GetRestrictedMenus

Any suggestion on how to solve this?:mad:

Thanks in advance
Elias
 
This line:
VB.NET:
BindingSourceRestrictedMenus.DataSource = DatasetRestrictedMenus
does not created any inherent link between the BindingSource and that variable. It takes the current value of that variable and assigns it to the BindingSource's DataSource. The fact that you later assign a new DataSet to that variable means nothing to the BindingSource, whose DataSource is still the old DataSet. In that case you would need to set the BindingSource's DataSource again.

That said, you could just repopulate the existing DataSet instead of creating a whole new one.
 
I do wish people would follow .net naming conventions instead of naming everything like a method/class - makes it a lot easier to work out what is going on

VB.NET:
'Bind all the bindings
_restrictedMenusBindingSource.DataSource = _restrictedMenusDataSet
_restrictedMenusBindingSource.DataSource = "SecurityRestrictions"

_controlMenusListBox.DataSource = _restrictedMenusBindingSource
_controlMenusListBox.DisplayMember = "FullName"
_controlMenusListBox.ValueMember = "ID"

Now to refresh:

VB.NET:
_securityRestrictionsTableAdapter.Fill(_restrictedMenusDataSet.SecurityRestrictions)
 

Latest posts

Back
Top