我正在尝试使用存储在我的服务器上的目录中的文件名来填充ComboBox,但是无处可去。
这是我正在使用的代码。我没有收到任何错误或任何错误,但组合框中没有出现任何错误。非常感谢您提供的任何帮助。
Try
If ComboBox1.SelectedItem = "Australia" Then
ComboBox2.Items.AddRange(File.ReadAllLines("ChartCountries\Australia.txt"))
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "FS Enhancer")
End Try
'Load Charts
Try
If ComboBox2.SelectedItem = "Bendigo (YBDG)" Then
Dim sf As String
For Each sf In Directory.GetFiles(My.Settings.ChartsURL & "AU/Bendigo/")
ComboBox3.Items.Add(sf)
Next
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "FS Enhancer")
End Try
提前致谢。
更新: 已经给出了下面的代码'加载图表自己的功能。还将代码更改为以下。但得到“URI格式不被接受”
'Load Charts
Try
If ComboBox2.SelectedItem = "Bendigo (YBDG)" Then
Dim dir = My.Settings.ChartsURL & "/AU/Bendigo"
For Each file As String In Directory.GetFiles(dir)
ComboBox3.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file))
Next
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "FS Enhancer")
End Try
感谢您的帮助。
答案 0 :(得分:0)
对于任何有兴趣的人,我设法让这个工作。
我首先使用Collection String将所有国家/地区放入第一个ComboBox。然后我上传了一个名为txt的文件,在这个例子中," Australia"到里面有城市名称的服务器。
Try
lstAirports.Items.Clear()
If lstCountries.SelectedItem = "Australia" Then
Dim client As WebClient = New WebClient()
Dim country As String = client.DownloadString(My.Settings.ChartURL & "Australia.rc")
Dim lines As String() = country.Split(New String() {ControlChars.CrLf}, StringSplitOptions.RemoveEmptyEntries)
lstAirports.Items.AddRange(lines)
End If End Try
机场名称:
If lstAirports.SelectedItem = "Melbourne (YMML)" Then
Dim client As WebClient = New WebClient()
Dim country As String = client.DownloadString(My.Settings.ChartURL & "Charts/AU/YMML.rc")
Dim lines As String() = country.Split(New String() {ControlChars.CrLf}, StringSplitOptions.RemoveEmptyEntries)
lblAboutAirport.Text = "About " & lstAirports.Text
txtBoxAirport.Text = "Melbourne Airport, also known as Tullamarine Airport, is the primary airport serving the city of Melbourne, and the second busiest airport in Australia. It was opened in 1970 to replace the nearby Essendon Airport" & vbNewLine & "The airport is 23 km (14 mi) from the city centre. The airport has its own postcode, which is Melbourne Airport, Victoria, 3045. This is adjacent to the suburb of Tullamarine."
lstCharts.Items.AddRange(lines)
End If
然后我上传了另一个文件,其中包含该区域机场的图表名称,并将其称为第三个组合框:
If lstCharts.SelectedItem = "YMML Aerodrome 1" Then
AxAcroPDF1.src = My.Settings.ChartURL & "Charts/AU/Melbourne/Aerodrome1.pdf #toolbar=0&navpanes=0"
End If
If lstCharts.SelectedItem = "YMML Aerodrome 2" Then
AxAcroPDF1.src = My.Settings.ChartURL & "Charts/AU/Melbourne/Aerodrome2.pdf #toolbar=0&navpanes=0"
End If
因此,在第三个ComboBox中单击图表的名称会在PDF阅读器中显示图表。