Si9004

Hi,

I have a tab control with 2 tab pages. Both pages have a datagridview on and show similar information.

I initially populate them with by using a bindingsource (bound to a binding list of custom objects). I then scan the bindingsource and dynamically create multiple unbound columns and populate the relevant cells.

This works fine for the first (displayed) tab but not the second.

If the first tab is displayed when the datagridview is populated the second DGV's unbound columns show null values. This doesn't happen the opposite way round (the unbound columns populate ok).

I created a collection of datagridviewcells so that i could monitor the cells to see when they were being changed back to null. Turns out they're not being changed, infact, all of the rows are being replaced with new rows!

I'm guessing this has something to do with the databinding and focus of the DGV but i can't detect any events happening when i activate the second tab with the DGV on!

Any help much appreciated!

 

** Forgot to mention - if i reload the data while the program's still running it works fine! But i don;t think the users would appreciate me telling them it's a 'feature' for them to have to click the button twice!



Re: Windows Forms Data Controls and Databinding Datagridview overwriting all rows if populated unfocussed!

Ken Tucker

Until a bound control is shown .net does not update it. This is done to improve performance. In cases like your it will cause problems.





Re: Windows Forms Data Controls and Databinding Datagridview overwriting all rows if populated unfocussed!

Si9004

Thanks for your reply.

The DGV appears to be populated before it recieves focus but clears it's row collection and repopulates the first time it's shown.

I've got round it simply by showing tabPage2, then tabPage1 before hydrating.

Thanks for your help