cargt3
cargt3

Reputation: 89

How to refresh tab that are not shown

I have 3 tabPages on tabControl and each tabPage have a pictureBox.

When i select a row in gridview it load images from files, and on selection i want refresh the 3 tabs with images. The problem is that pictureBox refresh only when i switch tabPage not when i change image. I tried to refresh, invalidate, or update controls but it dont work.

I find it:

"Controls contained in a TabPage are not created until the tab page is shown, and any data bindings in these controls are not activated until the tab page is shown."

How to solve that problem.

Upvotes: 0

Views: 1225

Answers (2)

Nadeem_MK
Nadeem_MK

Reputation: 7689

Since the tab won't load the controls until it is selected, one common workaround is to force the focus on the tabs programatically.

  1. Set tabControl visibility to false (to avoid user from seeing the focus change).
  2. Set focus on Tab2, then Tab3 and back to Tab1
  3. Set visibility of tabControl to True again.

The only drawback is that user will see a blink of screen, due to effect of visibility. In case you on't play with the visibility, user will see focus moving from tab to tab, which is much worse! :)

Upvotes: 0

Andrey Korneyev
Andrey Korneyev

Reputation: 26876

You can force-create your controls using reflection. For example

private void CreateControl(Control control)
{
    var method = control.GetType().GetMethod("CreateControl", BindingFlags.Instance | BindingFlags.NonPublic);
    method.Invoke(control, new object[] { true });
}

Upvotes: 0

Related Questions