【问题标题】:Get the first visible column in Ultragrid获取 Ultragrid 中的第一个可见列
【发布时间】:2013-05-17 09:38:25
【问题描述】:

我的ultragrid 中有许多列,其中包含用户定义的visibleinvisible 操作。现在我必须检查该列是否是网格中的第一个column。因为我有一些columnsindex 的帮助下明确绑定,所以我无法获得该列。它总是显示与第一个相同的column

//代码

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

   'Get the first cell column in the grid
   UltraGridCell = UltraGridRow.Cells(UltraGridColumn)

   If ('Check Here') Then

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

   Else
      UltraGridCell.Appearance.ResetImage()
   End If
Next

如何做到这一点?

【问题讨论】:

  • 我真的不明白你想要什么。您只是想获取网格的第一列吗?
  • 是的。因为如果我隐藏第一列,我有一些明确绑定的列,那么代码应该将第二列显示为第一列,现在在网格中作为第一列可见。我说清楚了吗?

标签: .net vb.net infragistics ultrawingrid


【解决方案1】:

我正在添加一个替代答案,因为它回答了标题提出的问题,并且可能是人们遇到此问题时正在寻找的内容。

WinGrid 将有一个或多个 ColScrollRegions 提供一个可滚动的标题区域,并且在 ColScrollRegion 之外有一个 VisibleHeaders 属性公开滚动区域的可见标题。

请注意,即使网格向右滚动并且可能不是网格中的第一列,这也会提供第一个可见列。当滚动区域的滚动位置一直向左时,则VisibleHeadersCollection中的第一个表头将返回网格中的第一列。

ColScrollRegions 由 DisplayLayout 上的 ColScrollRegions 属性访问,您可以通过以下方式访问第一个可见标题:

Me.ultraGrid1.DisplayLayout.ColScrollRegions(0).VisibleHeaders(0).Header

如果标题是 ColumnHeader,那么它将 Column 作为属性公开。

【讨论】:

    【解决方案2】:

    编辑: 此代码将为您提供第一个可见的列。

    Dim firstCol As UltraGridColumn = Nothing
            For Each col As UltraGridColumn In TransactionsGrid.DisplayLayout.Bands(0).Columns
                If Not col.Hidden Then
                    firstCol = col
                    Exit For
                End If
            Next
            If firstCol IsNot Nothing Then
                'Your code here
            End If
    

    【讨论】:

    • 对不起,这不起作用。我在网格中的第一列是隐藏的,第二列显示为第一列。现在代码应该将第二列显示为第一列,因为它现在是可见的。
    • 为了更具体和直接,我需要网格的第一个可见列。
    【解决方案3】:

    使用标志来检查选择了哪一列,这段代码可以正常工作。

    For Each UltraGridColumn In Me.TransactionsGrid.Rows.Band.Columns
    
           'Get the first cell column in the grid
           UltraGridCell = UltraGridRow.Cells(UltraGridColumn)
    
           If ('Check Here') Then
    
              'Set the cell image
              UltraGridCell.Appearance.Image = My.Resources.Tran_comment_161
              UltraGridCell.Appearance.ImageHAlign = HAlign.Right
              UltraGridCell.Appearance.ImageVAlign = VAlign.Top
    
           Else
              UltraGridCell.Appearance.ResetImage()
           End If
        Next 
    
     If (blnFlag) Then
                        Dim i = 0
                        For Each UltraGridColumn In Me.TransactionsGrid.Rows.Band.Columns
    
                            'Get the first cell of the column in the grid
                            UltraGridCell = UltraGridRow.Cells(UltraGridColumn)
    
                            If (UltraGridColumn.Hidden = False And i = 0) Then
    
                                'Set the cell image
                                UltraGridCell.Appearance.Image = My.Resources.Tran_comment_161
                                UltraGridCell.Appearance.ImageHAlign = HAlign.Right
                                UltraGridCell.Appearance.ImageVAlign = VAlign.Top
                                i += 1
                            Else
                                'Reset the image if other column
                                UltraGridCell.Appearance.ResetImage()
                            End If
    
                        Next
      End If
    

    【讨论】:

      猜你喜欢
      • 2013-12-19
      • 2017-02-14
      • 2014-12-07
      • 1970-01-01
      • 1970-01-01
      • 2011-02-24
      • 1970-01-01
      • 2012-01-12
      • 1970-01-01
      相关资源
      最近更新 更多