Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How do I split combobox text into 2 textboxes?

combobox split vb.net

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1 codegirl

codegirl

    CC Regular

  • Member
  • PipPipPip
  • 36 posts

Posted 31 March 2013 - 09:41 PM

Hello everyone,

 

 I need this help been trying to figure this out. How would I split Josh:Boyle from a combobox into 2 text boxes by clicking a button? The difficult is that it has a : for the split.

 

Here is a screenshot:

 

Attached Thumbnails

  • 5555555555555.jpg


#2 zeroGiven

zeroGiven

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 61 posts

Posted 01 April 2013 - 03:22 AM

Take a look at the string.Split() method. It should get you the result you want



#3 Zooner

Zooner

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 04 April 2013 - 03:45 PM

Dim names() As String = Combobox1.Text.Split(":")

TextBox1.Text = names(0)

TextBox2.Text = names(1)



#4 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 04 April 2013 - 08:54 PM

Dim names() As String = Combobox1.Text.Split(":")

TextBox1.Text = names(0)

TextBox2.Text = names(1)

 

That plus checking names.Count > 1 before assigning the values to the textboxes



#5 lespauled

lespauled

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1360 posts

Posted 05 April 2013 - 05:10 AM

absolutely.  Most of your work should be validation of the data values before populating the textboxes. 


My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth

#6 saintvitish

saintvitish

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 23 April 2013 - 10:47 AM

To sum up:

 

Dim names() As String = Combobox1.Text.Split(":")

If names.Count > 1 Then

     TextBox1.Text = names(0)

     TextBox2.Text = names(1)

Else

     MsgBox("Something went wrong. There is no colon in the combo box text.") 'Change this line as you want

End If



#7 AceInfinity

AceInfinity

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 313 posts

Posted 28 April 2013 - 03:29 AM

To sum up:

 

Dim names() As String = Combobox1.Text.Split(":")

If names.Count > 1 Then

     TextBox1.Text = names(0)

     TextBox2.Text = names(1)

Else

     MsgBox("Something went wrong. There is no colon in the combo box text.") 'Change this line as you want

End If

 

Only you shouldn't be declaring your string array like this: Dim names() As String

 

You should instead put the () after the type...


Microsoft MVP (2012) - .NET Programming | ®Crestron DMC-T Certified Programmer
Posted Image





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download