Public Class Form1
  Inherits System.Windows.Forms.Form
  Private Swimmers As ArrayList
  Private dTable As DataTable
  Private gAdapter As GridAdapter

  Private Sub init()
    Swimmers = New ArrayList()
    ReadFile()
    dTable = New DataTable("Kids")
    dTable.MinimumCapacity = 100
    dTable.CaseSensitive = False

    Dim column As DataColumn
    column = New DataColumn("Frname", System.Type.GetType("System.String"))

    dTable.Columns.Add(column)
    column = New DataColumn("Lname", System.Type.GetType("System.String"))

    dTable.Columns.Add(column)
    column = New DataColumn("Age", System.Type.GetType("System.Int16"))

    dTable.Columns.Add(column)

    DGrid.DataSource = dTable
    DGrid.CaptionVisible = False    'Bez opisu
    DGrid.RowHeadersVisible = False 'Bez nagłówków kolumn
    DGrid.EndInit()
    gAdapter = New GridAdapter(DGrid)
    lsKids.TabIndex = 0
  End Sub

#Region " Windows Form Designer generated code "

  Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call
    init()
  End Sub

  'Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
      If Not (components Is Nothing) Then
        components.Dispose()
      End If
    End If
    MyBase.Dispose(disposing)
  End Sub
  Friend WithEvents Moveit As System.Windows.Forms.Button
  Friend WithEvents lsKids As System.Windows.Forms.ListBox
  Friend WithEvents DGrid As System.Windows.Forms.DataGrid

  'Required by the Windows Form Designer
  Private components As System.ComponentModel.Container

  'NOTE: The following procedure is required by the Windows Form Designer
  'It can be modified using the Windows Form Designer.  
  'Do not modify it using the code editor.
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.Moveit = New System.Windows.Forms.Button()
    Me.lsKids = New System.Windows.Forms.ListBox()
    Me.DGrid = New System.Windows.Forms.DataGrid()
    CType(Me.DGrid, System.ComponentModel.ISupportInitialize).BeginInit()
    Me.SuspendLayout()
    '
    'Moveit
    '
    Me.Moveit.Location = New System.Drawing.Point(160, 72)
    Me.Moveit.Name = "Moveit"
    Me.Moveit.Size = New System.Drawing.Size(48, 24)
    Me.Moveit.TabIndex = 2
    Me.Moveit.Text = ">>"
    '
    'lsKids
    '
    Me.lsKids.Location = New System.Drawing.Point(24, 32)
    Me.lsKids.Name = "lsKids"
    Me.lsKids.Size = New System.Drawing.Size(128, 186)
    Me.lsKids.TabIndex = 0
    '
    'DGrid
    '
    Me.DGrid.CaptionVisible = False
    Me.DGrid.DataMember = ""
    Me.DGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText
    Me.DGrid.Location = New System.Drawing.Point(224, 32)
    Me.DGrid.Name = "DGrid"
    Me.DGrid.RowHeadersVisible = False
    Me.DGrid.Size = New System.Drawing.Size(256, 160)
    Me.DGrid.TabIndex = 1
    '
    'Form1
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(488, 273)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Moveit, Me.DGrid, Me.lsKids})
    Me.Name = "Form1"
    Me.Text = "Grid adapter"
    CType(Me.DGrid, System.ComponentModel.ISupportInitialize).EndInit()
    Me.ResumeLayout(False)

  End Sub

#End Region

  Private Sub ReadFile()
    Dim s As String
    Dim sw As Swimmer
    Dim fl As New vbFile("swimmers.txt")
    fl.OpenForRead()
    s = fl.readLine
    While Not fl.fEOF
      sw = New Swimmer(s)
      Swimmers.Add(sw)
      lsKids.Items.Add(sw.getName)
      s = fl.readLine
    End While
  End Sub

  Private Sub Moveit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Moveit.Click
    Dim i As Integer
    Dim sw As Swimmer
    i = lsKids.SelectedIndex
    If (i >= 0) Then
      sw = CType(Swimmers(i), Swimmer)
      gAdapter.addText(sw)
    End If
  End Sub
End Class
