none
How do I get the application to wait while the user chooses from a combobox RRS feed

  • Question

  • I have two webserver searches; the first gets information to use in the second. If there is more than one result from the first search I load the results into a combo box I then want the user to choose from a value in that combo box so I can pass it to the second websearch.

    I have tried giving the combobox the focus and 'doevents' but nothing seems to work.

    Is this possible?

    Thursday, August 15, 2019 8:38 AM

Answers

  • If the first operation gives more results, then maybe you should display a small modal form that allows the user to select one of the results. Then you can perform the second operation and fill the main form.

    • Marked as answer by seasider60 Wednesday, August 28, 2019 8:08 AM
    Thursday, August 15, 2019 8:50 AM

All replies

  • If the first operation gives more results, then maybe you should display a small modal form that allows the user to select one of the results. Then you can perform the second operation and fill the main form.

    • Marked as answer by seasider60 Wednesday, August 28, 2019 8:08 AM
    Thursday, August 15, 2019 8:50 AM
  • Hi seasider60,

    Welcome to the MSDN forum.

    According to your description, we can not judge the problem clearly. So please tell us what the type of your project is , what the webserver search is and how you load data into a combo box.

    Also, please share the key codes of your steps with us so that we will troubleshot your issue quickly.

    >>If your issue goes beyond our forum, we will help you redirect your issue to the right forum for better help. 

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Friday, August 16, 2019 2:48 AM
  • Hi seasider60,

    Yes, I recommend you could use "SelectedIndexChanged" event for combobox to implement it. Please refer sample below:

    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
                comboBox1.Items.Add("pop up ok");
                comboBox1.Items.Add("pop up yes");
                comboBox1.Items.Add("pop up good");
    
            }
    
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                try
                {
                    if (comboBox1.SelectedItem.ToString() == "pop up ok")
                        MessageBox.Show("ok");
                }
                catch
                { }
            }

    Result:

    Any feedback will be expected.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Friday, August 16, 2019 9:12 AM
  • My Apologies, the application is a VB desktop application written with VS community 2019. I use two types of websearch in TMDB, the first finds the TV series by title. If the search only returns one result I assume this is series I am looking for I then pass the series ID to the next websearch with finds all the details for the series. If the first search returns more than one result what I would like to do is fill a combobox with the results and get the user to choose the series. The problem is the code is not waiting for the user to choose from the combobox. currently Viorel's answer seems the most practical. Really just wanted to know if this is possible.

    Here is my code:

            ' Build the 'Search API' URL.

            Dim uri = New Uri("https://api.themoviedb.org/3/search/tv?" _
                               & "api_key=" & TMDBAPIKey _
                               & "&language=en-US" _
                               & "&query=" & sLvl1NodeName _
                               & "&page=1" _
                               & "&first_air_date_year=" & sFirstXmitYear)
            ' Retrieve the IMDB ID with an API Search function using the series title
            Try
                Dim Site = New WebClient()
                Answer = Site.DownloadString(uri)
            Catch ex As NullReferenceException
                Dim messagetext As String = "The 'Search API' from GetDetails popup failed with : " _
                & ex.Message & " for: Title=" & sLvl1NodeName
                Me.txtErrorMessageBox.Text = messagetext
                Exit Sub
            End Try
            ' Deserialise the answer
            Dim JsonElem As TMDBtitle = JsonConvert.DeserializeObject(Of TMDBtitle)(Answer)
            ' If the websearch finds only one result this is the TV series we want, if more than
            ' one result is found load the results into a combobox and get the user to choose.
            If JsonElem.results.Length = 1 Then
                Me.lblTVChooseSeries.Text = Me.lblTVChooseSeries.Text & "( " & JsonElem.results.Length & " )"
                popupID = JsonElem.results(0).id
            Else
                cmbChooseTVSeriesDetails.BeginUpdate()
                Me.lblTVChooseSeries.Text = Me.lblTVChooseSeries.Text & "( " & JsonElem.results.Length & " )"
                For Each titleresult In JsonElem.results
                    ComboSeriesChoice = titleresult.name & " | " &
                                        titleresult.id & " | " &
                                        titleresult.first_air_date & " | " &
                                        titleresult.overview
                    Me.cmbChooseTVSeriesDetails.Items.Add(ComboSeriesChoice)
                Next
                cmbChooseTVSeriesDetails.EndUpdate()
                Dim ChosenItem As String = Me.cmbChooseTVSeriesDetails.SelectedItem
                Dim itemchosen As String() = ChosenItem.Split(New Char() {" | "})
                popupid = itemchosen(1)
            End If
            ' Build the 'TV Search API' call URL.
            Dim urix = New Uri("https://api.themoviedb.org/3/tv/" _
                               & popupID & "?" _
                               & "api_key=" & TMDBAPIKey _
                               & "&language=en-US")
            Try
                Dim site = New WebClient()
                Answer = site.DownloadString(urix)              ' download the JSON from the server.
            Catch ex As NullReferenceException
                Dim MessageText As String = "The 'TV Search API' from GetDetails popup failed with : " _
                & ex.Message & " for: Title=" & sLvl1NodeName & " ID=" & popupID
                Me.txtErrorMessageBox.Text = MessageText
                Exit Sub
            End Try
            Dim jsonelemx = JsonConvert.DeserializeObject(Of TVResult)(Answer)

            lstDetailItems(0) = "Backdrop Path"
            lstDetailItems(1) = jsonelemx.backdrop_path
            lstDetailItems(2) = (String.Empty)
            Dim DelItems = New ListViewItem(lstDetailItems)
            Me.lstSeriesDetails.Items.Add(DelItems)
            lstDetailItems(0) = "Episode run time"
            lstDetailItems(1) = Convert.ToString(jsonelemx.episode_run_time(0))
            lstDetailItems(2) = (String.Empty)
            DelItems = New ListViewItem(lstDetailItems)
            Me.lstSeriesDetails.Items.Add(DelItems)

    Saturday, August 17, 2019 10:51 AM
  • My Apologies,

    The application is a windows desktop application developed in VS 2019 community.

    I have two websearches on TMDB site the first does a string search for a tv series I then get the ID for the series and do another search for all the series details. If the first search only contains 1 result then I assume the series is the one I want, I give the ID to the second search to get more details. If the first search contains more than one result I load the combo box and the user chooses the series. Many thanks for all your help

            ' Get the title from the lvl1 node the user clicked.
            If TreeView1.SelectedNode.Level <> 1 Then
                Exit Sub
            Else
                sLvl1NodeName = TreeView1.SelectedNode.Text
            End If
            ' Build the 'Search API' URL.
            Dim uri = New Uri("https://api.themoviedb.org/3/search/tv?" _
                               & "api_key=" & TMDBAPIKey _
                               & "&language=en-US" _
                               & "&query=" & sLvl1NodeName _
                               & "&page=1" _
                               & "&first_air_date_year=" & sFirstXmitYear)
            ' Retrieve the IMDB ID with an API Search function using the series title
            Try
                Dim Site = New WebClient()
                Answer = Site.DownloadString(uri)
            Catch ex As NullReferenceException
                Dim messagetext As String = "The 'Search API' from GetDetails popup failed with : " _
                & ex.Message & " for: Title=" & sLvl1NodeName
                Me.txtErrorMessageBox.Text = messagetext
                Exit Sub
            End Try
            ' Deserialise the answer
            Dim JsonElem As TMDBtitle = JsonConvert.DeserializeObject(Of TMDBtitle)(Answer)
            ' If the websearch finds only one result this is the TV series we want, if more than
            ' one result is found load the results into a combobox and get the user to choose.
            If JsonElem.results.Length = 0 Then
                Me.lblTVChooseSeries.Text = Me.lblTVChooseSeries.Text & "( " & JsonElem.results.Length & " )"
                popupid = JsonElem.results(0).id
            Else
                cmbChooseTVSeriesDetails.BeginUpdate()
                Me.lblTVChooseSeries.Text = Me.lblTVChooseSeries.Text & "( " & JsonElem.results.Length & " )"
                For Each titleresult In JsonElem.results
                    ComboSeriesChoice = titleresult.name & " | " &
                                        titleresult.id & " | " &
                                        titleresult.first_air_date & " | " &
                                        titleresult.overview
                    Me.cmbChooseTVSeriesDetails.Items.Add(ComboSeriesChoice)
                Next
                cmbChooseTVSeriesDetails.EndUpdate()
                Dim ChosenItem As String = Me.cmbChooseTVSeriesDetails.SelectedItem
                Dim itemchosen As String() = ChosenItem.Split(New Char() {" | "})
                popupid = itemchosen(1)
            End If
            ' Build the 'TV Search API' call URL.
            Dim urix = New Uri("https://api.themoviedb.org/3/tv/" _
                               & popupID & "?" _
                               & "api_key=" & TMDBAPIKey _
                               & "&language=en-US")
            Try
                Dim site = New WebClient()
                Answer = site.DownloadString(urix)              ' download the JSON from the server.
            Catch ex As NullReferenceException
                Dim MessageText As String = "The 'TV Search API' from GetDetails popup failed with : " _
                & ex.Message & " for: Title=" & sLvl1NodeName & " ID=" & popupID
                Me.txtErrorMessageBox.Text = MessageText
                Exit Sub
            End Try
            Dim jsonelemx = JsonConvert.DeserializeObject(Of TVResult)(Answer)

            lstDetailItems(0) = "Backdrop Path"
            lstDetailItems(1) = jsonelemx.backdrop_path
            lstDetailItems(2) = (String.Empty)
            Dim DelItems = New ListViewItem(lstDetailItems)
            Me.lstSeriesDetails.Items.Add(DelItems)
            lstDetailItems(0) = "Episode run time"
            lstDetailItems(1) = Convert.ToString(jsonelemx.episode_run_time(0))
            lstDetailItems(2) = (String.Empty)
            DelItems = New ListViewItem(lstDetailItems)
            Me.lstSeriesDetails.Items.Add(DelItems)
            lstDetailItems(0) = "First air date"
            lstDetailItems(1) = Convert.ToString(jsonelemx.first_air_date)
            lstDetailItems(2) = (String.Empty)
            DelItems = New ListViewItem(lstDetailItems)
            Me.lstSeriesDetails.Items.Add(DelItems)

    Monday, August 19, 2019 8:28 AM
  • Hi,

    Do you want to pause the program while the user chooses from a combobox?

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ' program stops for 3 seconds
            AddHandler ComboBox1.SelectedValueChanged, Sub()
                                                           Threading.Thread.Sleep(3000)
                                                       End Sub
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 20, 2019 2:12 AM
    Moderator
  • Hi Alex,

    Many thanks for your reply.

    The combo box is being loaded with the correct items but the selectedvaluechanged event is never fired because the user doesn't get the chance to click the dropdown before the program continues, even with the 3-sec pause. Not sure if this something to do with the way the controls are processed within the form.

    Tuesday, August 20, 2019 8:23 AM
  • Hi,

    How do users chooses from a combobox?

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 20, 2019 9:10 AM
    Moderator
  • Click the arrow on the right-hand side.

    ' Deserialise the answer
            Dim JsonElem As TMDBtitle = JsonConvert.DeserializeObject(Of TMDBtitle)(Answer)
    
            ' If the websearch finds only one result this is the TV series we want, if more than
            ' one result is found load the results into a combobox and get the user to choose.
            If JsonElem.results.Length = 1 Then
                Me.lblTVChooseSeries.Text = Me.lblTVChooseSeries.Text & "( " & JsonElem.results.Length & " )"
                popupid = JsonElem.results(0).id
            Else
                cmbChooseTVSeriesDetails.BeginUpdate()
                Me.lblTVChooseSeries.Text = Me.lblTVChooseSeries.Text & "( " & JsonElem.results.Length & " )"
                For Each titleresult In JsonElem.results
                    ComboSeriesChoice = titleresult.name & " | " &
                                        titleresult.id & " | " &
                                        titleresult.first_air_date & " | " &
                                        titleresult.overview
                    Me.cmbChooseTVSeriesDetails.Items.Add(ComboSeriesChoice)
                Next
                cmbChooseTVSeriesDetails.EndUpdate()
    
                Dim ChosenItem As String = Me.cmbChooseTVSeriesDetails.SelectedItem
                Dim itemchosen As String() = ChosenItem.Split(New Char() {" | "})
                popupid = itemchosen(1)
            End If
    
            ' Build the 'TV Search API' call URL. 
            Dim urix = New Uri("https://api.themoviedb.org/3/tv/" _
                               & popupID & "?" _
                               & "api_key=" & TMDBAPIKey _
                               & "&language=en-US")
    

    But the user isn't given the chance the code stops on the dim itemchosen as string line with 'Object reference not set to an instance of an object.' because nothing has been chosen.
     

    Tuesday, August 20, 2019 6:37 PM
  • Hi,

    Do you want to stop program while user click the drop-down arrow on the right?

     Private Sub ComboBox1_DropDown(sender As Object, e As EventArgs) Handles ComboBox1.DropDown
            Thread.Sleep(3000)
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 21, 2019 2:21 AM
    Moderator