Normally a databound winform only fires the getters for the properties which match textboxes, grids etc
But as I page through a collection (via BindingNavigator NextItem/PreviousItem), I'm finding that if I set a datagrid's DataSource to a property, then remove it, that property getter thereafter continues to fire even though the grid on the form is blank and is not asking for the data.
The only reason this bothers us is the getter has to go back to the data layer (which is a small performance hit) if it is fired for the first time on any given record. Our form has several grids under different tabs. So we thought it would be a perf improvement if the grids on the tabs not currently selected had their datasources set to nothing. And yet the getters are firing anyway (as soon as the tab & its grid have been selected at least once) ... which messes with our supposed perf improvement.
Simplified example:
Say I have form which pages through record cards for "Countries". On the form I have a two grids:
The first grid is for the country's "Cities" The second grid is for the country's "Rivers"
By default the cities grid is bound to Country.Cities By default the rivers grid isn't databound and stays empty.
If I page through my five test countries (USA, UK, France, Germany, Italy) my Country.Cities collection is accessed. Country.Rivers is not accessed. As you would expect. I write to the console every time Country.Cities or Country.Rivers is accessed so the output reads:
Country.Cities accessed
Country.Cities accessed
Country.Cities accessed
Country.Cities accessed
Country.Cities accessed
Bear with me.
If while viewing the UK I manually bind (e.g. through a dummy button) the Rivers grid to the Country.Rivers collection, then later page to France and manually unbind it (e.g. again explicitly, through a button) then continue paging through to Italy what I see is:
Country.Cities accessed
Country.Cities accessed
Country.Rivers accessed
Country.Cities accessed
Country.Rivers accessed
Country.Cities accessed
Country.Rivers accessed <-- ???
Country.Cities accessed
Country.Rivers accessed <-- ???
How come Germany & Italy are still asking for Rivers?
BTW here's the code under those two buttons:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RiversGrid.DataSource = Me.CountryBindingSource
RiversGrid.DataMember = "Rivers"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
RiversGrid.DataSource = Nothing
RiversGrid.DataMember = ""
RiversGrid.Dispose()
End Sub