Results 1 to 14 of 14

Thread: Reload or Refresh Form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    108

    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

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  3. #3
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: Reload or Refresh Form

    Hi,

    In your case code should look for example like this:

    VB Code:
    1. Dim text As String = ""
    2.  
    3. Select Case Me.ComboBox1.Text
    4.        Case "yellow"
    5.                 text = "yellow"
    6.         Case "blue"
    7.                 text = "blue"
    8. End Select
    9.  
    10. 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:
    1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2.         Dim text As String
    3.         text = Me.ComboBox1.Text
    4.         Me.TextBox1.Text = text
    5.     End Sub

    or simply by placing code into Combobox SelectedIndexChanged event handler:
    VB Code:
    1. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    2.         Me.TextBox1.Text = Me.ComboBox1.Text
    3.     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.

  4. #4
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Reload or Refresh Form

    You are already populating the text box!
    VB Code:
    1. TextBox1.Text = (SelectedItem)

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    108

    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

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    108

    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

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    108

    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

  8. #8
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Reload or Refresh Form

    Try this
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         Select Case CStr(Me.ComboBox1.SelectedItem)
    4.             Case "blue"
    5.                 Me.TextBox1.Text = "blue"
    6.                 MsgBox("we have blue")
    7.             Case "yellow"
    8.                 Me.TextBox1.Text = "yellow"
    9.                 MsgBox("we have yellow")
    10.         End Select
    11.  
    12.     End Sub

  9. #9
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    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"

  10. #10
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Reload or Refresh Form

    What is the purpose to refresh the form?
    You don’t need to refresh the form!

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    108

    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

  12. #12
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Reload or Refresh Form

    Then this is what you want
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim myColor As String = CStr(Me.ComboBox1.SelectedItem)
    3.         Select Case myColor
    4.             Case "blue"
    5.                 MsgBox("we have blue")
    6.             Case "yellow"
    7.                 MsgBox("we have yellow")
    8.         End Select
    9.         Me.TextBox1.Text = myColor
    10.     End Sub

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    108

    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

  14. #14
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    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
  •  



Click Here to Expand Forum to Full Width