Hi
OK, is the user selecting from a ComboBox not less efficient than just scrolling through a DataGridView (watching the UTC time is a good marker for searching).
Anyway, your design so we will go with that. Here is code that may help. It saves the user selected item (timezone to text file and region to xml file) as per the paths/filenames set at top of code (you would need to edit accordingly)
Give this a try. (NOTE: try as a stand alone test using this code with your paths/filenames)
' Form1 with DataGridView1 (empty),
' ComboBox1 (empty),
' Label1 and Label2 (Label2 for result)
Public Class Form1
Dim dt As New DataTable("Freddy")
Dim WithEvents BS As New BindingSource
' need to edit all paths/filenames to suit
Dim BasePath As String = My.Computer.FileSystem.SpecialDirectories.Desktop
Dim SourceDataFileXML As String = IO.Path.Combine(BasePath, "TimeZonesAndRegions.xml")
Dim OutputZoneFile As String = IO.Path.Combine(BasePath, "TimeZone.txt")
Dim OutputRegionFile As String = IO.Path.Combine(BasePath, "Regions.xml")
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
dt.WriteXml(SourceDataFileXML)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
With dt
.Columns.Add("Zone", GetType(String))
.Columns.Add("Region", GetType(String))
If IO.File.Exists(SourceDataFileXML) Then .ReadXml(SourceDataFileXML)
End With
BS.DataSource = dt
DataGridView1.DataSource = BS
With ComboBox1
.DataSource = BS
.DisplayMember = "Zone"
.ValueMember = "Region"
.AutoCompleteMode = AutoCompleteMode.SuggestAppend
.DropDownStyle = ComboBoxStyle.DropDown
.AutoCompleteSource = AutoCompleteSource.ListItems
End With
ComboBox1.DataBindings.Add("text", BS, "Zone", True, DataSourceUpdateMode.OnValidation)
Label2.DataBindings.Add("text", BS, "Region", True, DataSourceUpdateMode.OnValidation)
AddHandler BS.PositionChanged, AddressOf GetCurrent
End Sub
Sub GetCurrent()
Dim pos As Integer = BS.Position
Dim tz As String = dt(pos)(0)
Dim reg As String = dt(pos)(1)
SaveTZtxt(tz)
SaveREGtxt(reg)
End Sub
Sub SaveTZtxt(s As String)
Using sr As New IO.StreamWriter(OutputZoneFile, False)
sr.WriteLine(s)
End Using
End Sub
Sub SaveREGtxt(s As String)
Dim xmlDoc As New Xml.XmlDocument
Dim RegElement As Xml.XmlElement = xmlDoc.CreateElement("Region")
xmlDoc.AppendChild(RegElement).InnerText = s
xmlDoc.Save(OutputRegionFile)
End Sub
End Class