Results 1 to 10 of 10

Thread: [RESOLVED] drop down list

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    23

    Resolved [RESOLVED] drop down list


    hii.. hw can i build a form with two drop down lists( combo boxes type 0), one for students and the other for their study center code. when this form is loaded fill the lists from the arrays. if the user pulls down one of the list and clicks on a student the corresponding study center code is displayed in the text box of the other list?
    thnx for rplyin..

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: drop down list

    The main part depends on the way you save the students and their corresponding study centers.

    Your application needs to read in the data.
    Furthermore during the _load event you need to fill the dropdown lists with all students (probably their names) and all possible study centers (you would have to loop thru your data the get all possivble centers).

    When the user clicks on a student, use this click event to set the corresponding listindex of the study center dropdown.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3
    Junior Member
    Join Date
    Mar 2007
    Posts
    19

    Re: drop down list

    This does what you're looking for. Place code in a form with two combo boxes (combo1 & combo2). It populates the arrays itself which you will probably want to change. It asumes an Integer value for the codes and links the student combobox (combo1) with the codes using the ItemData property.

    Let me know if this helps..
    Code:
    'Arrays for storing student names and codes
    Private students(0 To 4) As String
    Private codes(0 To 4) As Integer
    'Match the selected student's itemdata with that of the codes' and select the correct one
    Private Sub Combo1_Click()
        Dim Code As Integer
        Dim i As Long
        Code = Combo1.ItemData(Combo1.ListIndex)
        For i = 0 To Combo2.ListCount - 1
            If Combo2.ItemData(i) = Code Then
                  Combo2.ListIndex = i
                  Exit For
            End If
        Next
    End Sub
    'Fill arrays and dropdowns
    Private Sub Form_Load()
        FillArrays
        FillDropDowns
    End Sub
    'Populate the arrays with students Mike1, Mike2 etc and corresponding codes 1111,1112 etc
    Private Sub FillArrays()
        students(0) = "Mike"
        students(1) = "John"
        students(2) = "Judie"
        students(3) = "Sue"
        students(4) = "Fred"
        
        codes(0) = 1 'Mike's code
        codes(1) = 2 'John's code
        codes(2) = 3 'Judie's code
        codes(3) = 4 'Sue's code
        codes(4) = 5 'Fred's code
    End Sub
    'Populate the comboboxes and link combo1 to cmobo2 using the Integer code value as the itemdata of the associated student
    Private Sub FillDropDowns()
        Dim i As Long
        For i = 0 To UBound(students)
            Combo1.AddItem students(i)
            Combo1.ItemData(Combo1.NewIndex) = codes(i)
            Combo2.AddItem codes(i)
            Combo2.ItemData(Combo2.NewIndex) = i
            
        Next
    End Sub
    .

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    23

    Question Re: drop down list

    Quote Originally Posted by Jimbo Jnr
    This does what you're looking for. Place code in a form with two combo boxes (combo1 & combo2). It populates the arrays itself which you will probably want to change. It asumes an Integer value for the codes and links the student combobox (combo1) with the codes using the ItemData property.

    Let me know if this helps..
    Code:
    'Arrays for storing student names and codes
    Private students(0 To 4) As String
    Private codes(0 To 4) As Integer
    'Match the selected student's itemdata with that of the codes' and select the correct one
    Private Sub Combo1_Click()
        Dim Code As Integer
        Dim i As Long
        Code = Combo1.ItemData(Combo1.ListIndex)
        For i = 0 To Combo2.ListCount - 1
            If Combo2.ItemData(i) = Code Then
                  Combo2.ListIndex = i
                  Exit For
            End If
        Next
    End Sub
    'Fill arrays and dropdowns
    Private Sub Form_Load()
        FillArrays
        FillDropDowns
    End Sub
    'Populate the arrays with students Mike1, Mike2 etc and corresponding codes 1111,1112 etc
    Private Sub FillArrays()
        students(0) = "Mike"
        students(1) = "John"
        students(2) = "Judie"
        students(3) = "Sue"
        students(4) = "Fred"
        
        codes(0) = 1 'Mike's code
        codes(1) = 2 'John's code
        codes(2) = 3 'Judie's code
        codes(3) = 4 'Sue's code
        codes(4) = 5 'Fred's code
    End Sub
    'Populate the comboboxes and link combo1 to cmobo2 using the Integer code value as the itemdata of the associated student
    Private Sub FillDropDowns()
        Dim i As Long
        For i = 0 To UBound(students)
            Combo1.AddItem students(i)
            Combo1.ItemData(Combo1.NewIndex) = codes(i)
            Combo2.AddItem codes(i)
            Combo2.ItemData(Combo2.NewIndex) = i
            
        Next
    End Sub
    .
    thnx for the rply but m unable to use that code.. error

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: drop down list

    What error and on what line did it occur?

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    23

    Re: drop down list

    [highlight = vb]
    actually i m beginner. so will u plz tell how to write the code in a step wise manner so that i can write it n run it correctly
    [/highlight]

  7. #7
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: drop down list

    Referring to your problem to connect the the drop down lists:
    What else do you need?
    Jimbo Jnr did give you all the code needed, as well he stated which controls you need to add to your application. This code should run!
    Referring to your problem to read the student and code data from a non specified storage place (textfile or database) you should search this forum!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    23

    Re: drop down list

    thnx bro..

  9. #9
    Member
    Join Date
    Nov 2005
    Posts
    48

    Resolved Re: [RESOLVED] drop down list

    here is what u r lookin for man
    download it from the attachment and code goes here too.
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const CB_SHOWDROPDOWN = &H14F
    'Written by Gaurav_Raj420
    Private Sub Command1_Click()
    On Error GoTo handler
    Dim sStr As String
    Dim Stud As Integer
    Dim ComItm() As String
    Dim Lup As Integer
    Stud = InputBox("How Much Students ?", "Students")
    ReDim ComItm(Stud)
    For Lup = LBound(ComItm) To UBound(ComItm)
        sStr = InputBox("Enter " & Lup & " Name")
        Combo1.AddItem sStr
    Next
    MsgBox "Students Entries Have Been Added " & vbCrLf & "See them now", vbExclamation, "Students Entries"
    SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 1, 1
    Exit Sub
    handler:
    MsgBox Err.Description & vbNewLine & Err.Number, vbCritical, "Error"
    End Sub
    
    Private Sub Command2_Click()
    On Error GoTo handler
    Dim sStr As String
    Dim StudyCntr As Integer
    Dim ComItm() As String
    Dim Lup As Integer
    StudyCntr = InputBox("How Much Study Centers ?", "Study Center")
    ReDim ComItm(StudyCntr)
    For Lup = LBound(ComItm) To UBound(ComItm)
        sStr = InputBox("Enter " & Lup & " Name")
        Combo2.AddItem sStr
    Next
    MsgBox "Study Center's Entries Have Been Added " & vbCrLf & "See them now", vbExclamation, "Study Center Entries"
    SendMessage Combo2.hwnd, CB_SHOWDROPDOWN, 1, 1
    Exit Sub
    handler:
    MsgBox Err.Description & vbNewLine & Err.Number, vbCritical, "Error"
    End Sub
    
    Private Sub Command3_Click()
    On Error GoTo handler
    Dim Srch As Integer
        Srch = InputBox("Enter Value To Search", "Search")
        MsgBox "Name = " & Combo1.List(Srch) & " Education Center = " & Combo2.List(Srch)
        Exit Sub
    handler:
    MsgBox Err.Description & vbNewLine & Err.Number, vbCritical, "Error"
    End Sub
    
    Private Sub Form_Load()
    Combo1.Text = ""
    Combo2.Text = ""
    Label1.Caption = "Students"
    Label2.Caption = "Study Centers"
    Command1.Caption = "E&nter Students Name"
    Command2.Caption = "&Enter Study Center"
    Command3.Caption = "&Search"
    Command1.Width = 2100
    Command2.Width = 2100
    Me.Width = 7000
    End Sub

    i know the topic is already [resolved] but i want to make this post because i made this prog for u adad..
    Attached Files Attached Files
    Last edited by gaurav_raj420; Mar 30th, 2007 at 05:39 AM. Reason: Tag-

    Please keep away yourself from smoking
    ______________________
    If you can't explain then don't write the hint because hint is always before when u have a problem. Okay?

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    23

    Re: [RESOLVED] drop down list

    ram ram bhai.. thnx bro..

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