Private Sub DataGrid1_ItemDataBound(sender As Object, e As DataGridItemEventArgs)
Select Case e.Item.ItemType
Case ListItemType.AlternatingItem, ListItemType.Item
’如果发现是分类标题行的话,则对其进行格式化
If e.Item.Cells(1).Text.Equals("-1") Then
'Format the SubHeading Columns
e.Item.Cells(0).Attributes.Add("align", "Left")
e.Item.Cells(0).ColumnSpan = 3
e.Item.Cells(0).Font.Bold = True
‘合拼为一个新的分类标题行,移除其中的单元格
e.Item.Cells.RemoveAt(2)
e.Item.Cells.RemoveAt(1)
e.Item.BackColor = Color.FromArgb(204,204,255)
End If
‘最后的所有分类的总计
If e.Item.Cells(0).Text.Equals("Total") Then
'Format the Main total column
e.Item.Cells(0).Attributes.Add("align", "Left")
e.Item.Cells(0).Font.Bold = True
e.Item.Cells(1).Font.Bold = True
e.Item.Cells(2).Font.Bold = True
e.Item.BackColor = Color.FromArgb(204,153,255)
End If
'如果是每个分类的小计的话,则设置相应的显示格式
If e.Item.Cells(0).Text.Equals("SubTotal") Then
'Format the subtotal columns.
e.Item.Cells(0).Attributes.Add("align", "Left")
e.Item.Cells(0).Text = "Sub Totals"
e.Item.Cells(0).Font.Bold = True
e.Item.Cells(1).Font.Bold = True
e.Item.Cells(2).Font.Bold = True
e.Item.Cells(0).Font.Italic = True
e.Item.Cells(1).Font.Italic = True
e.Item.Cells(2).Font.Italic = True
End If
End Select
End Sub |