Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 13th, 2004, 03:31 PM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default Problem Setting Tab Control selectedIndex

I'm having trouble setting a Tab Control Index under a specific circumstance and feel like I'm fighting with VS, as usual. Here's the scenario:

I have a Windows form with a tab control on it. Inside one of the tabs is a grid. When the user clicks on a row on the grid, the current window is closed and a new one opens where the user can edit data in the selected row. When done, the user clicks Update, and they should be taken back to the first screen, where the tab they were on should be redisplayed so the user appears to be back where they started.

To do this, I put code behind the TabControl.TabIndexChanged event to store the selected tab index in a global (this was a trick unto itself - tabpage.tabindexchanged and tabpage.enter don't seem to work at all, and tabpage.click only works if the user clicks inside the tab container and not on the tab selector as would be expected, but that's a different issue). Then when the user returns to the page, I should be able to simply set the tabcontrol.selectedindex and have the right tab displayed (and, btw, tabcontrol.tabpage(index).focus doesn't appear to work either).

Here's the rub. In the Windows Form Designer Generated Code part of the form code, the definition for the tabcontrol includes the statement:

tabcontrol.selectedindex = 0

That would be fine if it was just establishing a default value that could then be overridden in the form load as I intended, but this statement causes the tabcontrol.TabIndexChanged event to fire which overrides the global variable as described above, and I end up with the default value of 0 now in my global and when it hits the Form.Load it selects the wrong tab. I don't nuderstand why events are fired during Initialization, but I suppose MS thought they were doing me a favor somehow. They aren't!

Having found this, it seemed like the simplest solution was to change the Windows Form Generated code to reference my global variable instead of 0. This works great in the designer, but as soon as I close the form, VS appears to REBUILD the entire Windows Form Generated section of the code and my change is overwritten, with no warning whatsoever. I've also tried commenting the darn line out and it keeps coming back every time I save the form. It's maddening!

Is there any way to override this unauthorized change to my code, or prevent events from firing during form initialization? Or will I have to develop yet another workaround?
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to disable a tab on a tab control. dbradley VB.NET 6 April 14th, 2011 10:04 AM
Group box control Tab Focus problem suji C# 0 September 26th, 2008 01:26 AM
Calendar Control with Tab Control Slicemahn Access 1 June 12th, 2006 10:35 PM
comboBox selectedindex problem ColdFusion C# 4 May 12th, 2006 05:37 AM
SelectedIndex () in Windows 98!! problem thomaz C# 0 March 21st, 2005 02:29 PM

All times are GMT -4. The time now is 07:14 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.