Set grid column titles etc the easy way

Given a grid control, say a GridView, a ColumnView or a TableView, there are many ways you can set up the column header titles. This is the way that I have found to be both simple and most amenable to change. As an example...

    Private Sub LayoutMyGridView()
    
      Dim headers As String[]=["Species","Name","Gender","Size"]
      Dim idx As Integer
    
      myGridView.Columns.Count=headers.Count
      For idx = 0 to headers.Max
        myGridView.Columns[idx].Title = headers[idx]
      Next
    
    End

Just include a call to LayoutMyGridView in Form_Open().

Thus, all that is needed to add, delete or change a column title is an edit to the "headers" string array.

Want more?

By adding more local arrays (and a bit of sanity checking) you can set other column attributes of the grid in the same way!

    Private Sub LayoutMyGridView()
    
      Dim headers As String[]=["Species","Name","Gender","Size"]
      Dim widths As Integer[]=[120,120,30,35]
      Dim idx As Integer
    
      If widths.Count<>headers.count then Error.Raise("Programmer cannot count!")
    
      myGridView.Columns.Count = headers.Count
      For idx = 0 to headers.Max
        myGridView.Columns[idx].Title = headers[idx]
        myGridView.Columns[idx].Width = widths[idx]
      Next
    
    End