I have 4 DataGridView controls on my form. The grids are named grdG1, grdG2, grdG3 and grdG4. (Remember that's 1, 2, 3, and 4) I want to control the ColumnAdded sub for all of them in the same code block. The columns are added at runtime and need to be a certain width depending on which column index it is. The first two columns are wide and all the rest should be 40 pixels wide. I also need to set the ForeColor for each new column depending on the value in my Course.Assignment class.

The code below works for grdG1, and I could just copy it 3 more times and changed the numbers, but I think there should be a way to do it with the (ByVal sender).name and CType or DirectCast (neither of which I fully understand yet) and get the number from the grid name. Actually, I need to be able to do stuff in the rest of the program depending on which grd has been clicked, edited, and so on.

vb Code:
  1. Private Sub grd_ColumnAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles grdG1.ColumnAdded ', grdG2.ColumnAdded
  2.  
  3.         Dim i As Integer = e.Column.Index
  4.         Select Case i
  5.             Case 0
  6.                 grdG1.Columns(0).Width = DefaultNameColumnWidth
  7.                 grdG1.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
  8.                 grdG1.Columns(0).Frozen = True
  9.                 'grdG1.Columns(0).DefaultCellStyle = Font.helpme
  10.             Case Else
  11.                 grdG1.Columns(i).Width = 40
  12.                 grdG1.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
  13.  
  14.                 Select Case Trim(Course.Assignment(1, i).GradeType)
  15.                     Case "Test"
  16.                         grdG1.Columns(i).DefaultCellStyle.ForeColor = Color.Red
  17.                     Case "Homework"
  18.                         grdG1.Columns(i).DefaultCellStyle.ForeColor = Color.Black
  19.                     Case "9 Weeks Test"
  20.                         grdG1.Columns(i).DefaultCellStyle.ForeColor = Color.Blue
  21.                     Case "Semester Test"
  22.                         grdG1.Columns(i).DefaultCellStyle.ForeColor = Color.Green
  23.                 End Select
  24.         End Select
  25.     End Sub