2013-05-17 18 views
1

我的ultragrid中有多少列具有用戶定義的visibleinvisible操作。現在我必須檢查該列是否是網格中的第一個column。因爲我有一些columns這是明確綁定在index的幫助下,我不能得到列。總是顯示與第一個相同的column獲取Ultragrid中的第一個可見列

//代碼

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 

如何實現這一目標?

+0

我真的不明白你想要什麼。你是否想要獲得網格的第一列? –

+0

是的。因爲我有一些顯式綁定的列,如果我隱藏第一列,那麼代碼應該顯示第二列作爲第一列,現在可以在第一列顯示在網格中。我清楚了嗎? – iamCR

回答

0

有一個標誌來檢查選擇哪一列,這段代碼工作正常。

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 
0

編輯: 此代碼將爲您帶來第一個可見的列。

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 
+0

對不起,這不起作用。網格中的第一列是隱藏的,第二列顯示爲第一列。現在代碼應該將第二列顯示爲第一列,因爲現在可見。 – iamCR

+0

爲了更具體和直接我需要網格的第一個可見列。 – iamCR

+0

好的,沒問題。編輯過的版本適合你嗎? –

1

我加入了一個備選答案,因爲它回答了由標題問,可能是什麼人找,如果他們遇到這個問題的問題。

WinGrid將有一個或多個ColScrollRegions,它提供了一個滾動區域的標題並且不在ColScrollRegion中,這是一個VisibleHeaders屬性,該屬性公開滾動區域的可見標題。

請注意,這將提供第一個可見列,即使網格向右滾動並且可能不是網格中的第一列。當滾動區域的滾動位置一直向左移動時,VisibleHeadersCollection中的第一個標題將返回網格中的第一列。

的ColScrollRegions由上DisplayLayout的ColScrollRegions屬性來訪問,你可以訪問第一個可見的標題:

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

如果標題是的columnHeader,那麼它會暴露列的屬性。

相關問題