【问题标题】:Loop into next column of Ultragrid循环到 Ultragrid 的下一列
【发布时间】:2013-05-11 04:36:35
【问题描述】:

我正在使用 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

我怎样才能做到这一点?

【问题讨论】:

  • 不要用类名(UltraGridColumn、UltraGridRow、UltraGridCell)调用这些变量。这非常令人困惑。你的实际代码有什么问题?
  • 这工作正常,但我需要修改,如果当前在第二列中的循环我需要并行循环第三列并重置单元格。
  • 让我明白。您需要在每一行上循环,如果当前行第二列中的值无效,则重置当前行第三列中的图像?
  • 主要逻辑是,我必须在某些条件下为某些行设置第一列中的图像,如果用户隐藏该列,则该列中设置的图像应该移动到第一列现在可见。如果他撤销该列以使其可见,则图像应再次移回。我说清楚了吗?

标签: .net vb.net foreach ultrawingrid


【解决方案1】:

所以假设 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 行)

【讨论】:

  • 我在两列中都得到了图像。但我只需要在可见的网格的第一列中。
  • 当用户选择要显示的两列时,我必须绑定到第一列并删除第二列。同样,有 4 列可以使可见和不可见
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多