|
-
Jul 12th, 2007, 02:46 AM
#1
Thread Starter
Hyperactive Member
[2005] 4 Grids - One Sub
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:
Private Sub grd_ColumnAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles grdG1.ColumnAdded ', grdG2.ColumnAdded
Dim i As Integer = e.Column.Index
Select Case i
Case 0
grdG1.Columns(0).Width = DefaultNameColumnWidth
grdG1.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
grdG1.Columns(0).Frozen = True
'grdG1.Columns(0).DefaultCellStyle = Font.helpme
Case Else
grdG1.Columns(i).Width = 40
grdG1.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
Select Case Trim(Course.Assignment(1, i).GradeType)
Case "Test"
grdG1.Columns(i).DefaultCellStyle.ForeColor = Color.Red
Case "Homework"
grdG1.Columns(i).DefaultCellStyle.ForeColor = Color.Black
Case "9 Weeks Test"
grdG1.Columns(i).DefaultCellStyle.ForeColor = Color.Blue
Case "Semester Test"
grdG1.Columns(i).DefaultCellStyle.ForeColor = Color.Green
End Select
End Select
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|