Re: [2005] 4 Grids - One Sub
Oh and I tried this... but the form wouldn't even load so something's wrong.
vb Code:
Dim grd As DataGridView = CType(sender, DataGridView)
Dim nw As Integer = Integer.Parse(Microsoft.VisualBasic.Right(grd.Name, 1))
Dim i As Integer = e.Column.Index
Select Case i
Case 0
grd.Columns(0).Width = DefaultNameColumnWidth
grd.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
grd.Columns(0).Frozen = True
'grd.Columns(0).DefaultCellStyle = Font.helpme
Case Else
grd.Columns(i).Width = 40
grd.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
Select Case Trim(Course.Assignment(nw, i).GradeType)
Case "Test"
grd.Columns(i).DefaultCellStyle.ForeColor = Color.Red
Case "Homework"
grd.Columns(i).DefaultCellStyle.ForeColor = Color.Black
Case "9 Weeks Test"
grd.Columns(i).DefaultCellStyle.ForeColor = Color.Blue
Case "Semester Test"
grd.Columns(i).DefaultCellStyle.ForeColor = Color.Green
End Select
End Select
Re: [2005] 4 Grids - One Sub
The 'sender' parameter is always a reference to the object that raised the event. It will always refer to the correct DGV. You simply need to cast it as the correct type to access its members.
Re: [2005] 4 Grids - One Sub
Isn't that what I did in line 1 of the 2nd code I posted?
But something there is killing the form before it gets loaded.
Re: [2005] 4 Grids - One Sub
Your cast is correct, although I'd suggest DirectCast over CType. If the form won't load it's nothing to do with the cast. Remove the rest of the code and start adding it back bit by bit until it stops working. Then you know what the problem is. Problem solving techniques in programming are no different to problem solving techniques in other areas.
Re: [2005] 4 Grids - One Sub
Presumably columns are being added during the creation of the form and some of that code is invalid at that point. Put a breakpoint at the top of the code and then step through to see where the issue is. I think a breakpoint in an event handler should be hit during creation.