i've been looking around on how to make a combobox list choice to access a webpage on webbrowser. For example, if i choose the first item in the combobox wich is named "Google" then i would press on the button next to it to access google on the webbrowser.
I got this code but it doesn't work, once i choose the first option, nothing happens.
If ComboBox1.SelectedIndex = 1 Then
WebBrowser1.Navigate("https://www.google.ca/?gws_rd=ssl")
End If
I seems so close, but i have no clues why it doesn't work..
Try this...
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Select Case ComboBox1.SelectedItem
Case "Please Select"
MsgBox("ERROR - No selection made in dropdown box!")
Case "Google"
WebBrowser1.Navigate("www.google.com")
Case "Microsoft"
WebBrowser1.Navigate("www.microsoft.com")
Case "Stack Overflow"
WebBrowser1.Navigate("www.stackoverflow.com")
End Select
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'
ComboBox1.Items.Add("Please Select")
ComboBox1.Items.Add("Google")
ComboBox1.Items.Add("Microsoft")
ComboBox1.Items.Add("Stack Overflow")
ComboBox1.SelectedIndex = 0
'
End Sub
Private Sub WebBrowser1_Navigating(sender As Object, e As WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
ProgressBar1.Visible = True
With ProgressBar1
.Minimum = 0
.Maximum = 50
.Step = 5
End With
For index As Integer = 0 To 50 Step 5
ProgressBar1.Value = index
System.Threading.Thread.Sleep(35)
Next
End Sub
End Class
Is the item that's selected first? The index is 0-based. Meaning the first item in the list is index #0. Try it with selectedindex = 0.
Related
This is my first time working with VB.Net It's a college assignment and is already due for submission.I want to create a simple program that determines if a user has Ebola or not. So, there is a list of checkbox containing the core symptoms of Ebola. If the user selects 4 or more there should be a prompt message saying the user most likely has Ebola otherwise user does not have Ebola.
I have created the form and it works but don't know how to implement the checkbox into numbers that will be summed up.
Here is the code for the form
Public Class Checkbxvb
Private Sub Checkbxvb_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Label1.Text = "Click to select the symptoms you are having"
CheckBox1.Text = "Fever"
CheckBox2.Text = "Loss of appetite"
CheckBox3.Text = "sore throat"
CheckBox4.Text = "Gastrointestinal Symptoms"
CheckBox5.Text = "Unexplained bleeding or bruising"
CheckBox6.Text = "Loss of weight"
Button1.Text = "Submit"
Button2.Text = "Close"
End Sub
I want to create a button that will collect the user input like I said earlier on. Thanks
If you are using a CheckListBox you can used its CheckedItems collection Count property to get what you need.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If CheckedListBox1.CheckedItems.Count > 3 Then
MessageBox.Show("You may have Ebola.")
Else
MessageBox.Show("You probably don't have Ebola.")
End If
End Sub
If you are using CheckBox controls add them to a List(Of T). The T stands for Type. Create a variable for the list at Form level so it can be seen from the Form.Load and the button click. Then you can loop through your collection and increment a counter when the Checked property is True.
Private CkBxList As New List(Of CheckBox)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
CkBxList.AddRange({CheckBox1, CheckBox2, CheckBox3, CheckBox4})
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim counter As Integer
For Each cb In CkBxList
If cb.Checked Then
counter += 1
End If
Next
If counter > 3 Then
MessageBox.Show("You may have Ebola.")
Else
MessageBox.Show("You probably don't have Ebola.")
End If
End Sub
As you can see the code is much simpler with a CheckedListBox. Try to use the control that best suits your purpose.
I have 4 combobox in my visual basic;
ComboBox1 has 3 items: Vehicle, Motorbikes, None
ComboBox2 has 4 items: sportbike, casual bikes and sportcar,casual cars
ComboBox3
ComboBox4
I KINDLY need a code that will let me do the following:
Make combobox 2,3,4 invisible until I make a selection on combobox 1 i.e. I will choose vehicle and later progress to select sportscar meanwhile combobox 3 and 4 are invisible. In short, the next combo box only appears after making a selection on the previous one.
On combobox 1, if "none" is selected the other 2,3,4 remains invincible .
On the forms Load event you need to set combo boxes 2,3 and 4 to visible=False. Then on the ComboBox1_SelectedIndexChanged event you can change combobox2 to visible=True and then do the same for each progression. The code is shown below. You will also need to decide how you want to reset previous box. In other words do you want to comboboxes 2, 3, and 4 to once again become invisible if you change from Motorbikes to none in combobox1?
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox2.Visible = False
ComboBox3.Visible = False
ComboBox4.Visible = False
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedItem="None" then
ComboBox2.Visible=False
ComboBox3.Visible=False
ComboBox4.Visible=False
Else
ComboBox2.Visible = True
End If
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox3.Visible = True
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox4.Visible = True
End Sub
End Class
In your designer file, set the Visible property of 2, 3, and 4 to false.
Then in your code file use the following code:
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim showComboBox = Not String.IsNullOrWhitespace(ComboBox1.Text) AndAlso ComboBox1.Text <> "None"
ComboBox2.Visible = showComboBox
ComboBox3.Visible = showComboBox
ComboBox4.Visible = showComboBox
End Sub
What this does is set a Boolean variable equal to if the Text of ComboBox1 is not an empty string and not "None". It then sets the Visible property of the other ComboBox controls to the result.
I have a list view with check box. I want to make the button visible, if item in listView is checked. If there's no checked item visible = false.
Another quick example...
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
ListView1_ItemChecked(Nothing, Nothing)
End Sub
Private Sub ListView1_ItemChecked(sender As Object, e As ItemCheckedEventArgs) Handles ListView1.ItemChecked
Button1.Visible = (ListView1.CheckedItems.Count > 0)
End Sub
Private Sub MOOElv_ItemChecked(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles MOOElv.ItemChecked
Dim iCount As Integer
For i = 0 To MOOElv.Items.Count - 1
If MOOElv.Items(i).Checked = True Then
iCount = 1
End If
If iCount >= 1 Then
consumebtn.Visible = True
Else
consumebtn.Visible = False
End If
Next
End Sub
Thank you i got my own solution i just put a loop inside an event handler, then first determine the amount of items and if checked the button will visible :D
I would like to code a button that after 3 clicks, links the user to my site. The first 2 should generate a code in the textbox and the last one should then link them. This is what i have so far
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
ProgressBar1.Increment(3)
If ProgressBar1.Value = 100 Then
TextBox1.Text = "Thank you"
Timer1.Stop()
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If RadioButton1.Checked = True Then
Timer1.Start()
ElseIf RadioButton2.checked = True Then
Timer1.Start()
Else
TextBox1.Text = "Please Select Option"
End If
End Sub
I dont know what is the use of ProgressBar and Timer. But if you wan to know how many times user has click on a button, a counter variable should do.
Private _clickCounter As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
_clickCounter += 1
If _clickCounter = 3 Then
MsgBox("3 times")
_clickCounter = 0
'link to your site
Else
'generate code in textbox
End If
End Sub
Use an integer that increases each time the button is clicked and a Select Case statement to detect that;
Dim NumberOfClicks As Integer = 0
Dim webAddress As String = "http://www.YourWebsite.com/"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
number = number + 1
Select Case number
Case 1
''''' Code for your textbox
Case 2
''''' Code for your textbox
Case 3
Process.Start(webAddress)
End Sub
This should do. Please mark my answer as solved if it helps.
Looking to save combobox items to my.settings collection. I developed a webbrowser and a combobox will be my address bar. I am attempting to save a history of visited sites.
I tried the below code and it doesnt work. It errors out with "Object reference not set to an instance of an object":
Went into settings added MyItems for the name, and then select System.Collections.Specialized.StringCollection as the data type. Then onload is the below:
For Each i As String In My.Settings.MyItems
ComboBox1.Items.Add(i)
Next
FormClosing and ive tried FormClosed: For now i put it in a button event to save it for testing
My.Settings.MyItems.Clear()
For Each i As String In ComboBox1.Items
My.Settings.MyItems.Add(i)
Next
I love this site very much! So I came back to post the correct code that will correctly save and load combobox entries to my.setting! This has been tested as working!!!
Private Sub Form1_FormClosing(
sender As Object,
e As FormClosingEventArgs) Handles Me.FormClosing
My.Settings.Categories.Clear()
For Each item In ComboBox1.Items
My.Settings.Categories.Add(item.ToString)
Next
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each item In My.Settings.Categories
ComboBox1.Items.Add(item)
Next
ComboBox1.SelectedIndex = 0
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ComboBox1.Items.Add(TextBox1.Text)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If ComboBox1.Items.Count > 0 Then
Dim Index As Int32 = ComboBox1.SelectedIndex
ComboBox1.Items.RemoveAt(Index)
If Index - 1 <> -1 Then
ComboBox1.SelectedIndex = Index - 1
End If
End If
End Sub