循环进入Ultragrid的下一列

get 发布于 2019-03-15 .net 最后更新 2019-03-15 14:08 1 浏览

我使用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
我怎样才能做到这一点?
已邀请:

yut

赞同来自:

因此,假设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
您还可以使用标准... 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)