1

I have a problem with controls nested in a TabControl. I have a TabControl with n TabPages, with a DataGridView on each TabPage. Each DataGridView has a CheckBoxC column. I populate all datagridviews with different datasources (so each has different types of data). This is working ok!


I have added a ComboBox column so I can select all the rows on all DataGridViews. I do this programmatically (on a button click), and the counting of the selection is ok, except that the ticks are not added to checkBox cell of DataGridViews except on TabPage #1 (the one that I can see on startup).


If I click all the tabPages before I go and select all the rows in DataGridViews, the code works fine, and the ticks are added to all the rows (like I wanted).

But why this does not work without clicking all the tabPages? Is there any bug or something of TabControl?

Mitja Bonca
  • 4,268
  • 5
  • 24
  • 30
  • This is by design, binding only occurs when a control is visible. It is an optimization, you'll need to deal with that. – Hans Passant May 20 '12 at 16:26
  • So I have to bind data for each datagridview when appropriate tabPage is selected? This cannot be true, because the data are binded jsut fine - only ticks (for checkBox cells) are not added - when I set Value property of it to true. – Mitja Bonca May 20 '12 at 16:34
  • I think you might find a solution in my answer to [Does data binding work on invisible control?][1] [1]: http://stackoverflow.com/questions/943473/does-data-binding-work-on-invisible-control – Hasani Blackwell May 20 '12 at 16:55

2 Answers2

1

My workaround was to add this in the load event of the form.

this.tabcontrol1.BindingContext = this.BindingContext;
neildt
  • 5,101
  • 10
  • 56
  • 107
0

I know this answer is correct for WPF, not positive about WinForms though. With WPF at least, it's a visually based interface, so the program does not load any of the objects/controls/etc on other tabs until they are clicked on. So it wouldn't be a bug, it's a part of the design.

I had a similar problem with trying to clear all textboxes on multiple tabs with a single button. I never did get it working, but I know there should be a way by using a combination of VisualTreeHelper and a foreach statement.

Again, this is based off of WPF and not WinForms, but hopefully it can point you in the right direction as to how to solve it.

David Hall
  • 32,624
  • 10
  • 90
  • 127
Keven M
  • 972
  • 17
  • 47