What is the correct code for selecting an item from the combobox to display in textbox for Visual Studio 2005?
-
I know it is a "Select case" code. I want to select something in a combobox and the information would show up in the textbox. I used it in VB6 I can not get it to work in Visual Studio 2005. Is this code below correct because it does not work: Select Case DirectCast(sender, ComboBox).Name Case "Paul" TextBox4.Text = ("Paul Selected") Case "John" TextBox4.Text = ("John Selected") Case "Luke" TextBox4.Text = ("Luke Selected") End Select
-
Answer:
This will work, Select Case DirectCast(sender, _ comboBox).SelectedItem.ToString notice that ".SelectedItem.ToString" has been added to the the code that you have written will return the name assigned to the combox control: i.e. ComboBox1 the code above will return the value of what you have selected. I'd change youre code to do this as well: text4.text = "" ' clear the previous text dim cb as string cb = DirectCast(sender, ComboBox).SelectedItem.ToString TextBox4.Text = cb & " Selected" this will add the value of whatever you select to the textbox. Since the value entered only differs by name you dont need to use a select case statement Hope this helps
Johnny T at Yahoo! Answers Visit the source
Other answers
I take it this code is in the TextChanged event of the combo box you are using? Does DirectCase take 2 parameters? Only thing I can think of was to use the 'as' keyword somewhere, but that's the C# in me talking. For example: Select Case DirectCast(sender as CombBox).Name
Storm Sams
Related Q & A:
- How can you change the line color in Visual Studio?Best solution by Stack Overflow
- How to Create Visual Studio 2013 Extension?Best solution by Stack Overflow
- Why doesn't ClickOnce in Visual Studio deploy content files from dependent assemblies?Best solution by Stack Overflow
- How to embed localized resources in Visual Studio?Best solution by codeproject.com
- What are the main parts of visual basic 2005?Best solution by msdn.microsoft.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.