Ace Master Posted August 28, 2003 Posted August 28, 2003 He there. I am a beginer in vb and I'am trying to use the tabcontro.The problem is that I can't use it. :) I have this tabcontrol (tab) with two options. I have a web browser control (web) now...when I make a click on tabpage1 to go url1 ,and when I click on tabpage 2 to go url 2 in the web browser. I tried to put a click event to tabpage1 like : Private Sub TabPage1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabPage1.Click web.Navigate("http://www.microsoft.com") End Sub and similary to tab page2 .. whay this don't work ? thanks a lot. Quote
pjv Posted August 28, 2003 Posted August 28, 2003 Without seeing more code it's really too hard to see what's wrong. What you've posted looks fine to me.. IF web.Navigate works okay and you've setup the tab pages correctly, etc. Pete Quote
*Experts* Volte Posted August 28, 2003 *Experts* Posted August 28, 2003 Use the TabControl.SelectedIndexChanged event. The TabPage's click event only fires (as far as I know) when you click on the background of the tab - not when you change the tab selected. Quote
Ace Master Posted August 29, 2003 Author Posted August 29, 2003 Without seeing more code it's really too hard to see what's wrong. What you've posted looks fine to me.. IF web.Navigate works okay and you've setup the tab pages correctly, etc. Pete What more code ?? I need to write some code for tabpages? I just define them in proprieties window. tab1 and tab2..... thanks ps. how I use TabControl.SelectedIndexChanged ? ..I need somehow to link this with tab pages....but how ?? I know ..I know...but I am a beginner :) Quote
Mehyar Posted August 29, 2003 Posted August 29, 2003 to use the selected index changed Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged If TabControl1.SelectedIndex = 0 Then 'User clicked Tab1 'do what ever you want here ElseIf TabControl1.SelectedIndex = 1 Then 'User clicked tab2 'do what ever you want here End If End Sub Hope this helps, Quote Dream as if you'll live forever, live as if you'll die today
Ace Master Posted September 26, 2003 Author Posted September 26, 2003 thanks , but I have some weird problems here... If I have: Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged If TabControl1.SelectedIndex = 1 Then web1.Navigate2("http://some url.") ElseIf TabControl1.SelectedIndex = 2 Then web1.Navigate2("http://some url.") End If End Sub ... Is working....when I change de second an thirth tab ..the url is changing there....but I need this to work on first tab and second , so I need the code below....right ??? Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged If TabControl1.SelectedIndex = 0 Then web1.Navigate2("http://some url.") ElseIf TabControl1.SelectedIndex = 1 Then web1.Navigate2("http://some url.") End If End Sub but with this code .... index 0 changed....etc... I ceive this error at compilation: An unhandled exception of type 'InvalidActiveXStateException' occurred in axinterop.shdocvw.dll what this means ??? thanks. Quote
Mehyar Posted September 26, 2003 Posted September 26, 2003 OK try this Add a private variable Private FinishedLoading as Boolean = False Then in your Form_Load event add befor End Sub FinishedLoading = True Then your selectedIndexChanged will be like this Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged If FinishedLoading Then If TabControl1.SelectedIndex = 0 Then web1.Navigate2("http://some url.") ElseIf TabControl1.SelectedIndex = 1 Then web1.Navigate2("http://some url.") End If Hope this helps End If End Sub Quote Dream as if you'll live forever, live as if you'll die today
Ace Master Posted September 26, 2003 Author Posted September 26, 2003 hi. You will not going to belive that..but....now is working with a verry simple modification in my code. I replaced "Private Sub TabControl1_SelectedIndexChanged" with Private Sub TabControl1_click" behavior and now is working even if I put 0 ...weird anyway... but all the thanks...who knows when I will need your advice. Quote
Mehyar Posted September 26, 2003 Posted September 26, 2003 The code i gave you will also work. The reason that error is happening is that the SelectedINdexChanged is called while the control is being initialized. And then the event is executed but maybe the Web control has not been initialized so an exception occurs. Converting it to the click solved it because a click event isnot raised while the control is being initialized. Adding the variable i told you about will force the code in the Selected Index Changed to not to execute until the form has finished loading. Quote Dream as if you'll live forever, live as if you'll die today
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.