Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load joinCells(MyDataGrid, 1) END Sub
Private Sub joinCells(ByVal dg As DataGrid, ByVal column As Integer) Dim numRow As Integer numRow = dg.Items.Count
Dim baseIndex As Integer = 0
While (baseIndex < numRow) Dim nextIndex As Integer nextIndex = baseIndex + 1 Dim baseCell As TableCell baseCell = dg.Items(baseIndex).Cells(column)
While (nextIndex < numRow)
Dim nextCell As TableCell nextCell = dg.Items(nextIndex).Cells(column)
If getText(baseCell) = getText(nextCell) Then If (baseCell.RowSpan = 0) Then baseCell.RowSpan = 2 Else baseCell.RowSpan += baseCell.RowSpan End If dg.Items(nextIndex).Cells.Remove (nextCell) nextIndex += nextIndex Else Exit While End If End While baseIndex = nextIndex End While End Sub
Private Function getText(ByVal tc As TableCell) ↓!!!!!この下の行でエラー!!!!!!↓ Dim dblc As DataBoundLiteralControl = CType(tc.Controls(0), DataBoundLiteralControl) Return dblc.Text End Function
エラー内容は、 指定された引数は、有効な値の範囲内にありません。パラメータ名 : index です。
分類:[.NET]
まさしです、度々失礼します。
DataGridコントロールの同一列内のセルの結合のとき、
実行すると以下の箇所でエラーになります。
なぜでしょうか?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
joinCells(MyDataGrid, 1)
END Sub
Private Sub joinCells(ByVal dg As DataGrid, ByVal column As Integer)
Dim numRow As Integer
numRow = dg.Items.Count
Dim baseIndex As Integer = 0
While (baseIndex < numRow)
Dim nextIndex As Integer
nextIndex = baseIndex + 1
Dim baseCell As TableCell
baseCell = dg.Items(baseIndex).Cells(column)
While (nextIndex < numRow)
Dim nextCell As TableCell
nextCell = dg.Items(nextIndex).Cells(column)
If getText(baseCell) = getText(nextCell) Then
If (baseCell.RowSpan = 0) Then
baseCell.RowSpan = 2
Else
baseCell.RowSpan += baseCell.RowSpan
End If
dg.Items(nextIndex).Cells.Remove (nextCell)
nextIndex += nextIndex
Else
Exit While
End If
End While
baseIndex = nextIndex
End While
End Sub
Private Function getText(ByVal tc As TableCell)
↓!!!!!この下の行でエラー!!!!!!↓
Dim dblc As DataBoundLiteralControl = CType(tc.Controls(0), DataBoundLiteralControl)
Return dblc.Text
End Function
エラー内容は、
指定された引数は、有効な値の範囲内にありません。パラメータ名 : index
です。
TableCell は、System.Web.UI.WebControls 名前空間
DataBoundLiteralControl は、System.Web.UI 名前空間です
尚、これは、
http://www.atmarkit.co.jp/fdotnet/dotnettips/092joincells/joincells.html
を参考にしました。