DataGrid合併行

王朝c#·作者佚名  2006-01-09
宽屏版  字体: |||超大  

Private Sub UnitDataGridItem(ByVal intCell As Integer)

Dim objDataGridItem As DataGridItem

Dim strCell1 As String = ""

Dim strCell2 As String = ""

Dim objLiteralControl As LiteralControl

Dim intSpan As Integer = 1

Dim objDataGridItemToSpan As DataGridItem

Dim i, j As Integer

Dim strTemp As String

For i = 0 To DataGrid1.Items.Count - 1

intSpan = 1

objLiteralControl = CType(DataGrid1.Items(i).Cells(intCell).Controls(0), LiteralControl)

strCell1 = objLiteralControl.Text

For j = i + 1 To DataGrid1.Items.Count - 1

objLiteralControl = CType(DataGrid1.Items(j).Cells(intCell).Controls(0), LiteralControl)

strCell2 = objLiteralControl.Text

If strCell1 = strCell2 Then

intSpan += 1

DataGrid1.Items(i).Cells(intCell).RowSpan = intSpan

DataGrid1.Items(j).Cells(intCell).Visible = False

Else

Exit For

End If

Next

i = j - 1

Next

End Sub

除了設定RowSpan 外,還要把下面行的Visible 設成False,否則不起作用,底下會多出一個column.這個DataGrid的每個cell中都包含一個LiteralControl,如果沒有的話,就直接用DataGrid1.Items(i).Cells(intCell).Text即可.參數intCell ,是指要合併的那個列.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有