コード例 #1
0
        /// <summary>
        /// Fill the combobox with matching stations from the input of the combobox for the start station.
        /// </summary>
        private void FillComboboxWithMatchingStartStations()
        {
            try
            {
                // request stations from the API
                Stations stations = _transportHandler.GetStations(cmbStartLocation.Text);

                // clear the combobox so it does not over populate with false and non-distinct stations
                cmbStartLocation.Items.Clear();

                // if the request returned no stations, return and cancel operation
                if (stations.StationList.Count == 0)
                {
                    return;
                }

                foreach (Station station in stations.StationList)
                {
                    // if name of the station is empty, dont display it
                    if (string.IsNullOrEmpty(station.Name))
                    {
                        continue;
                    }

                    cmbStartLocation.Items.Add(station.Name);
                }

                // the operation causes the index of the combobox selection to be set to the beginning. to prevent this, following operation is done
                cmbStartLocation.SelectionStart = cmbStartLocation.Text.Length;
            }
            catch
            {
                // this operation is done so that the user wont be notified, when the service request threw an exception, after pressing a single button
                return;
            }
        }