Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need your help guuuys. Im new to vb.net. Programming is not my Major though. Can I ask how can I change ID using combo box?
For example.
I have Metal, Furniture, etc inside a combo box. Now, i want to drop down combo box then I click Metal, textbox must Show. Metal-0000#, but I dont know how to code it. Please help. Thankss.
Posted
Updated 12-Aug-13 19:50pm
v3
Comments
Sergey Alexandrovich Kryukov 12-Aug-13 23:57pm    
If "programming is not your major though", don't ask "how can I change ID?" — because this is programming.

I'm fed up with problems of people doing nearly full-time programming jobs, but finding millions of excuses based on the claim "I don't go in for programming". Very convenient...
If you do some job, do it well...

Okay, let's wrap it up: Not a valid question, not enough relevant information, not informative. And you also need to tag the UI library or application type you are using...

—SA
ChiPats 13-Aug-13 1:32am    
Sorry for that sir. I just need programming for my Thesis. That's why I need it. Im willing to learn programming. So I hope you can help me. So sorry.
Sergey Alexandrovich Kryukov 13-Aug-13 1:37am    
No need to apologize before me, those are your problems. Please explain the problem in more detail and tag UI you are using.
—SA
ChiPats 13-Aug-13 1:47am    
What is UI Sir? App that im using? Im using Vb 2010. Hmm, this is the one that Im using

\\ While SQLDataReader.Read
\\ autoID = read(0) + 1
\\ If combobox1.SelectedItem <> "" Then
\\ textbox1.Text = Format(read(0) + 1, combobox1.SelectedItem + ("-0000#"))
\\ End If

It work but when I add new item in combo box. It errors. Sorry for my actions. Hope ya understand.
Sergey Alexandrovich Kryukov 13-Aug-13 1:57am    
Oh... You probably need to live in the .NET sphere for a while, not taking critical or more complex tasks... This is "User Interface". The .NET FCL (Again? Okay, "Framework Class Library". You see, I myself hate abbreviations, but working in the framework of some Framework requires understanding of few...)... the .NET FCL has several unrelated UI libraries: WPF, System.Windows.Forms, ASP.NET, Silverlight, some other from 3rd-parties, and more.

Say, when you say "ComboBox", one would ask: "which one?!..." Full type name please...

—SA

ChiPats, for you I will highly recommend spending a VERY SMALL amount of money at this site, http://www.learnvisualstudio.net/[^]

These are by far, some of the most informative videos that are, at the same time, very easy to understand.

I used them for a short while, it was money well spent. It will open your eyes to the full world of possibilities that wait for you in visualBasic.net development. I am now addicted to programming because of this.

I was especially caught up in database issues and not even understanding how they work. Now I'm in the process of developing a database and interface for the company where I work. I't because of this guy.
 
Share this answer
 
Try this to get started:

VB
Public Class Form1
    Dim itemList As List(Of Item)


    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        MyBase.OnLoad(e)
        Dim i As Integer
        Dim n As Integer
        Dim s As String
        Dim obj As Item

        Me.itemList = New List(Of Item)
        Me.itemList = Item.ListAll()
        n = Me.itemList.Count

        For i = 0 To n - 1
            obj = Me.itemList.Item(i)
            s = obj.name
            Me.ComboBox1.Items.Add(s)
        Next
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim i As Integer
        Dim n As Integer
        Dim txt As String
        Dim obj As Item

        n = Me.itemList.Count
        i = Me.ComboBox1.SelectedIndex
        If i >= 0 & i < n Then
            obj = Me.itemList(i)
            txt = obj.name & obj.id.ToString() & "#"

            Me.TextBox1.Text = txt
        End If

    End Sub
End Class

Public Class Item
    Public name As String
    Public id As Integer

    Public Sub New(ByVal i As Integer, ByVal itemName As String)
        name = itemName
        id = i
    End Sub

    Public Shared Function ListAll() As List(Of Item)
        Dim newItem As Item

        Dim data(0 To 2) As String
        data(0) = "Metal"
        data(1) = "Furniture"
        Dim items As List(Of Item)
        items = New List(Of Item)

        For i As Integer = 0 To 1
            newItem = New Item(i, data(i))
            items.Add(newItem)

        Next

        Return items

    End Function

End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900