Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9233855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:39:04+00:00 2026-06-18T06:39:04+00:00

I have a form with a 2 listboxes. Here, listbox1 is populated with names

  • 0

I have a form with a 2 listboxes. Here, listbox1 is populated with names of actors and actresses. If a name is selected from listbox1, listbox2 should show the title(s) of movie(s) where that name is involved. If another name is selected, listbox2 will show title(s) of movie(s) that 2 name is involved.

Call Connect()
    With Me
        STRSQL = "select mTitle from selectmovie where cName = '" & lstNames.SelectedItem & "'"
        Try
            myCmd.Connection = myConn
            myCmd.CommandText = STRSQL
            myReader = myCmd.ExecuteReader
            If (myReader.Read()) Then
                myReader.Close()
                myAdptr.SelectCommand = myCmd
                myAdptr.Fill(myDataTable)
                lstTitle.DisplayMember = "mTitle"
                lstTitle.ValueMember = "mTitle"

                If myDataTable.Rows.Count > 0 Then
                    For i As Integer = 0 To myDataTable.Rows.Count - 1
                        lstTitle.Items.Add(myDataTable.Rows(i)("mTitle"))
                    Next
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End With

There’s no error. When I select 1 item the result is correct but it leaves many space..here the screen shot of my form: http://www.flickr.com/photos/92925726@N06/8445945758/in/photostream/

The output becomes worse when I selected actor3: http://www.flickr.com/photos/92925726@N06/8445945724/in/photostream/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:39:05+00:00Added an answer on June 18, 2026 at 6:39 am

    Your main problem seems to be that you do not clear your lstTitle control before re-loading it with the new selection. Therefore, each time you select a new name, it will add all the titles for that name to the existing list of titles that are already loaded. Also, instead of using an integer to iterate all the indexes, it is easier to just use a For Each loop:

    lstTitle.Items.Clear()
    For Each row As DataRow In myDataTable.Rows
        lstTitle.Items.Add(row("mTitle"))
    Next
    

    However, I must also mention that you really should also be using a parameter in your query rather than dynamically building the SQL statement like that, for instance:

    myCmd.CommandText = "select mTitle from selectmovie where cName = @name"
    myCmd.Parameters.AddWithValue("name", lstNames.SelectedItem)
    

    To select all the movies where all of the multiple selected actors are involved, you would need to add an additional condition to your where clause for each actor, for instance:

    Dim builder As New StringBuilder()
    builder.Append("select distinct mTitle from selectmovie where ")
    For i As Integer = 0 to lstNames.SelectedItems.Count - 1
        Dim parameterName As String = "@name" & i.ToString()
        If i <> 0 Then
            builder.Append("and ")
        End If
        builder.Append(parameterName)
        builder.Append(" in (select cName from selectmovie where mTitle = m.mTitle) ")
        myCmd.Parameters.AddWithValue(parameterName, lstNames.SelectedItems(i))
    Next
    myCmd.CommandText = builder.ToString()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method in a Windows form called Beginning that reads names from
I have listBox1 and listBox2 which are loaded with some files from a directory.
I have a form with a dropdownbox two listboxes and two buttons on it.
I have a TListBox on a form, and items are added with listbox1.ItemIndex :=
I have a new batch form where user can select books from a div
Here is how I form my xml from a ListBox new XElement(City, lstCities.Items .Cast<ListItem>()
I have data comming back from web service in the form of a ObservableCollection<string>
I have a small problem here. I want to list my files from a
I have one Form, that opens another one. The user writes some information here.
I have several listboxes in a form that I can drag and drop items

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.