views:

152

answers:

1

Hello,

I have a complex problem, could you please help me.

The problem:

I have a form with a TabControl. There are two TabPages in the first is a dataGridView and in the second are multiple comboboxes.

DataGridView is filled with data from Table1, on the other tab the first combobox datasource is set to TableCB1, the second combobox to TableCB2 etc.

Between TableCB1, TableCB2 ... are DataRelations like (TableCB1.ID->TableCB2.ParentID). I'm using databindings to bind current columns from table to controls.

When I open the form, first tabPage (dataGridView) is filled and works ok, but if I select the second TabPage (with comboboxes) then the combobox selected items are not correct selected!!! Only the first combobox is set correctly but all other have selected the first item in datasource until I change the bindingsource position or make dataset.rejectchanges().

But if make TabPage two to be shown on form load, then the combobox items are selected correctly!

I know it's a very specific problem but, hope somebody could help me to solve this problem.

I'm doing it on .NET3.5 and winforms.

Thanks.

A: 

The reply in this thread might be what you need:

DataBinding doesn't occur on Controls until the Controls are created. A TabPage creates child controls only after the TabPage has been made visible. To get DataBinding to occur, you'll need to force the child controls on the TabPage to be created and one way you can do that is by showing/hiding the TabPage (as you have discovered).

Jacob Seleznev