|
-
Aug 28th, 2006, 04:34 PM
#1
Thread Starter
Lively Member
Reload or Refresh Form
Hi,
I would like to know how I can reload a form or repopulate a textbox after button click event.
Here is the code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SelectedItem As String = ComboBox1.Text '("Whats your f color")
Select Case LCase(ComboBox1.Text)
Case "blue"
MsgBox("we have blue")
Case "yellow"
MsgBox("we have yellow")
TextBox1.Text = (SelectedItem)
Me.Refresh()
End Select
End Sub
So after user selects yellow, a msg box appears display we have yellow, I all so want texbox1.text to be updated with the selectedItem, which will be yellow.
Thanks,
Mike
-
Aug 28th, 2006, 04:45 PM
#2
Re: Reload or Refresh Form
InitializeComponents() is the method resposible of putting all items in your form
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Aug 28th, 2006, 04:46 PM
#3
Addicted Member
Re: Reload or Refresh Form
Hi,
In your case code should look for example like this:
VB Code:
Dim text As String = ""
Select Case Me.ComboBox1.Text
Case "yellow"
text = "yellow"
Case "blue"
text = "blue"
End Select
Me.TextBox1.Text = text
but if you want to populate textbox with value from combobox you don't need Select Case. You can do it simply like that:
VB Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim text As String
text = Me.ComboBox1.Text
Me.TextBox1.Text = text
End Sub
or simply by placing code into Combobox SelectedIndexChanged event handler:
VB Code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Me.TextBox1.Text = Me.ComboBox1.Text
End Sub
Hope this helps.
Regards,
sweet_dreams
using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts. 
-
Aug 28th, 2006, 04:47 PM
#4
Re: Reload or Refresh Form
You are already populating the text box!
VB Code:
TextBox1.Text = (SelectedItem)
-
Aug 28th, 2006, 05:07 PM
#5
Thread Starter
Lively Member
Re: Reload or Refresh Form
HI, Sweet_dreams
But if I do it that way, how can I tell which SelectItem the user has selected, my code is more involved then this, but I did not what to fill up post with code.
Dim text As String = ""
because if I have predined items, I can see your point, but I also would like to capture other user inputed items too.
So with that how can I get it to get predfined items and user added items to populate the textbox1
Thanks for your help, great explaination
Mike
-
Aug 28th, 2006, 05:14 PM
#6
Thread Starter
Lively Member
Re: Reload or Refresh Form
Hi, Sweet_dreams
This does show blue in textbox1.text, but if a user inputs something else, how can I capture that.
Dim SelectedItem As String = ComboBox1.Text '("Whats your f color")
Dim Text As String = ""
Select Case LCase(ComboBox1.Text)
Case "blue"
Text = "Blue"
MsgBox("we have blue")
Me.TextBox1.Text = Text
Case "yellow"
MsgBox("we have yellow")
TextBox1.Text = (SelectedItem)
End Select
Thanks,
Mike
-
Aug 28th, 2006, 05:18 PM
#7
Thread Starter
Lively Member
Re: Reload or Refresh Form
Sorry forgot to explain
TextBox1.Text = (SelectedItem)
why will this not work?
Also why do you refer to Me.TextBox1
I was trying Me.Refresh
any Ideas
Mike
-
Aug 28th, 2006, 05:21 PM
#8
Re: Reload or Refresh Form
Try this
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Select Case CStr(Me.ComboBox1.SelectedItem)
Case "blue"
Me.TextBox1.Text = "blue"
MsgBox("we have blue")
Case "yellow"
Me.TextBox1.Text = "yellow"
MsgBox("we have yellow")
End Select
End Sub
-
Aug 28th, 2006, 05:26 PM
#9
Re: Reload or Refresh Form
Also why do you refer to Me.TextBox1
your form is a class object, to refer any property in a class you use "Me.PropertyName"
-
Aug 28th, 2006, 05:28 PM
#10
Re: Reload or Refresh Form
What is the purpose to refresh the form?
You don’t need to refresh the form!
-
Aug 28th, 2006, 05:30 PM
#11
Thread Starter
Lively Member
Re: Reload or Refresh Form
HI, VBDT
This works good, but still will not let you, get selected user input,
say a user types red, but red it not in my items list, it will not populate the textbox1.text field??
Thanks all everyone help in this matter.
Mike
-
Aug 28th, 2006, 05:33 PM
#12
Re: Reload or Refresh Form
Then this is what you want
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myColor As String = CStr(Me.ComboBox1.SelectedItem)
Select Case myColor
Case "blue"
MsgBox("we have blue")
Case "yellow"
MsgBox("we have yellow")
End Select
Me.TextBox1.Text = myColor
End Sub
-
Aug 28th, 2006, 05:39 PM
#13
Thread Starter
Lively Member
Re: Reload or Refresh Form
I found the fix:
I had to move the textbox1.text out of the select case statement, to below the end select?
in my program code I have many other line of code that write and read the registry, so why does this textbox1.text command not work inside the select case statements?
Thanks,
Mike
Select Case CStr(Me.ComboBox1.SelectedItem)
Case "blue"
TextBox1.Text = ComboBox1.Text ' I fix it by moving this statement out of the Select Case to below the End Select?
MsgBox("we have blue")
Case "yellow"
Me.TextBox1.Text = "yellow"
MsgBox("we have yellow")
End Select
TextBox1.Text = ComboBox1.Text
-
Aug 28th, 2006, 05:50 PM
#14
Re: Reload or Refresh Form
It does work in select case statement! Thus if you select ‘blue’ or ‘yellow’ colors the textbox will show the color names in it but if you select different colors from those the textbox will be empty because the textbox assigns value if the select case condition is true!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|