Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. prevent System.Windows.Forms.TabControl.ControlCollection to change SelectedIndex at Remove method

prevent System.Windows.Forms.TabControl.ControlCollection to change SelectedIndex at Remove method

Scheduled Pinned Locked Moved C#
databasewpfwcfhelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Martin 0
    wrote on last edited by
    #1

    Hello everybody! I'm working on an application which has UserControls (GUI pages) with TabControls on it. This TabControls are Usercontrols derived from Windows.Forms.TabControl. Same to TabPage. The TabPage class has a "Visible" property which removes the TabPage from TabControl.TapPages property, if it's set to false. This Visible property is refreshed over an userdefined binding mechanism. This means if I change my page, the Visible property of the TabPages will be refreshed. On default the SelectedIndex property of the TabControl is set to "0". Now what's my problem: I allways had strange visual effects as the TabPages where removed from the Collection. I saw the different TabPages flickering until all the TabPages where removed. Thank's to Lutz Roeder's reflector I found out that the framework is forcing the SelectedIndex property after removing the tabpage.

    public override void Remove(Control value)
    {
    base.Remove(value);
    if (value is TabPage)
    {
    int index = this.owner.FindTabPage((TabPage) value);
    if (index != -1)
    {
    this.owner.RemoveTabPage(index);
    this.owner.SelectedIndex = Math.Max(index - 1, 0);
    }
    this.owner.UpdateTabSelection(false);
    }
    }

    I now whant to find a solution which prevents the SelectedIndex property to change when removing a TabPage. What I was thinking of: As the SelectedIndex property is not virtual I'm not able to override it in my TabControl class. Maybe I could inherit a TabPageCollection class, for my TabPages property of TabControl class, which overrides the "Remove" method. And after that ???? Thanks for your time. All the best, Martin

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups