Sean,
I just realized that I did not read your original post accurately. This is my understanding at this point.
1. You are reading in multiple records from your text file
2. One of the Fields in the record is "Name".
3. You want to populate a combobox with the name fields.
4. The textboxes should auto update with based on the combobox value.
5. This is a WPF usercontrol.
I only put the combobox and 2 textboxes on the UC, but you should get the idea. The code behind the UC will need to be adjusted to match your data. It reads your DB into a DataTable and uses binding to handle the rest.
Edit Modified to address comments:
Imports System.IO
Imports System.Data
Partial Public Class UserControl1
Private Dt As New System.Data.DataTable
Private source As New Binding
Private fn As String = "d:\my documents\fields.txt"
Private Sub UserControl1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
Dim r As System.Data.DataRow
With Dt
.Columns.Add("FX", GetType(String)) 'added this for you preceeding tab
.Columns.Add("Name", GetType(String))
.Columns.Add("F1", GetType(String)) ' replace F# with something more meaningful
.Columns.Add("F2", GetType(String))
.Columns.Add("F3", GetType(String))
.Columns.Add("F4", GetType(String))
.Columns.Add("F5", GetType(String))
.Columns.Add("F6", GetType(String))
.Columns.Add("F7", GetType(String))
.Columns.Add("F8", GetType(String))
.DefaultView.Sort = "[Name] ASC"
Dim sr As New IO.StreamReader(fn)
Do While sr.Peek() <> -1
r = .NewRow
r.ItemArray = sr.ReadLine().Split(New Char() {vbTab(0)}, 9, System.StringSplitOptions.None)
.Rows.Add(r)
Loop
sr.Close()
End With
ComboBox1.DataContext = Dt
TextBox1.DataContext = Dt
TextBox2.DataContext = Dt
End Sub
' this is the method to write out the datatable
Public Sub WriteDB()
Dim sw As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(fn, False)
Dim line As New System.Text.StringBuilder(1000)
For Each r As DataRow In Dt.Rows
line.Length = 0
For Each obj As Object In r.ItemArray
If obj IsNot DBNull.Value AndAlso Not String.IsNullOrEmpty(obj.ToString) Then
line.Append(obj.ToString)
End If
line.Append(vbTab)
Next
sw.WriteLine(line.ToString)
Next
sw.Close()
End Sub
Private Sub ComboBox1_GotFocus(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles ComboBox1.GotFocus
Dt.DefaultView.RowFilter = Filter()
ComboBox1.EditableTextBox.CaretIndex = ComboBox1.Text.Length
ComboBox1.EditableTextBox.SelectionLength = 0
ComboBox1.IsDropDownOpen = True
ComboBox1.StaysOpenOnEdit = True
End Sub
Private Function Filter() As String
Return "[Name] Like '" & ComboBox1.Text & "*'"
End Function
Private Sub ComboBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles ComboBox1.KeyUp
Dim tmp As String = ComboBox1.Text
Dt.DefaultView.RowFilter = Filter() ' "[Name] Like '" & ComboBox1.Text & "*'"
ComboBox1.SelectedIndex = -1
ComboBox1.Text = tmp
ComboBox1.EditableTextBox.CaretIndex = ComboBox1.Text.Length
End Sub
Private Sub ComboBox1_LostFocus(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles ComboBox1.LostFocus
ComboBox1.IsDropDownOpen = False
' ****** Hack.
' There must be a better way to force this update, if Name is not in the data
Dim tmp As String = ComboBox1.Text
ComboBox1.Text = ""
ComboBox1.Text = tmp
' ***** End Hack
End Sub
End Class
' created a custom combobox so that I could access the internal textbox
Public Class myCombo
Inherits System.Windows.Controls.ComboBox
Friend ReadOnly Property EditableTextBox() As TextBox
Get
Return (TryCast(MyBase.GetTemplateChild("PART_EditableTextBox"), TextBox))
End Get
End Property
End Class
<UserControl x:Class="UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="269" Height="263"
xmlns:MyNamespace="clr-namespace:WpfApplication1"
>
<Grid Height="122" Width="200">
<MyNamespace:myCombo
Height="23" HorizontalAlignment="Left" Margin="5,0,0,0" x:Name="ComboBox1"
VerticalAlignment="Top" Width="150" IsSynchronizedWithCurrentItem="True"
IsEditable="True"
IsTextSearchEnabled="False"
ItemsSource="{Binding}"
DisplayMemberPath="Name"
/>
<TextBox Margin="5,51,45,48" Name="TextBox1" Text="{Binding Path=F1}"/>
<TextBox Margin="5,0,0,13.5" Height="20" Name="TextBox2" Text="{Binding Path=F2}"
VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="150" />
</Grid>
</UserControl>