0

我正在使用 foreach 按列循环进入网格,在循环进入一列时,我必须进行验证并循环到下一个可见列,即验证并重置列单元格的图像。

//代码

            For Each col In Me.TransactionsGrid.Rows.Band.Columns

                If (col.Hidden = False) Then

                    'Get the first cell of the first column in the grid
                    cell= row.Cells(col.Index)

                    'Set the cell image
                    cell.Appearance.Image = My.Resources.Tran_comment_161
                    cell.Appearance.ImageHAlign = HAlign.Right
                    cell.Appearance.ImageVAlign = VAlign.Top


                    'Loop in to the next visible column and reset the image of the cell
                        //Code here
                    cell= row.Cells(UltraGridColumn.Index + 1)

                    'Reset the cell image
                    cell.Appearance.ResetImage()

                    Exit For
                End If
            Next

我怎样才能做到这一点?

4

1 回答 1

0

因此,假设 ActiveRow 是您要更新的行,此代码会将您的图像设置在未隐藏的 ActiveRow 的第一个单元格中

For Each col In Me.TransactionsGrid.ActiveRow.Band.Columns
     UltraGridCell cell= row.Cells(col)
     If (col.Hidden = True) Then
         cell.Appearance.ResetImage();
     else              
        cell.Appearance.Image = My.Resources.Tran_comment_161
        cell.Appearance.ImageHAlign = HAlign.Right
        cell.Appearance.ImageVAlign = VAlign.Top
        Exit For
     End If            
Next

您还可以使用标准 for...next 和索引器来控制循环

For x = 0 To Me.TransactionsGrid.ActiveRow.Band.Columns.Count - 1
     UltraGridColumn col = Me.TransactionsGrid.ActiveRow.Band.Columns(x)
     UltraGridCell cell= row.Cells(col)
     If (col.Hidden = True) Then
         cell.Appearance.ResetImage();
     else              
        cell.Appearance.Image = My.Resources.Tran_comment_161
        cell.Appearance.ImageHAlign = HAlign.Right
        cell.Appearance.ImageVAlign = VAlign.Top
        Exit For
     End If            
Next

第二种方法的好处是允许您更改列集合中的起始索引(某行for x = 1 to Me.TransactionsGrid.ActiveRow.Band.Columns.Count - 1

于 2013-05-16T11:41:23.433 回答