Question

I am having number of columns in my ultragrid with userdefined visible and invisible operations. Now i have to check wheather the column is the first column in the grid. since i have some columns which is binded explicitly with the help of index i cant get the column. Always it shows the same column as the First one.

//Code

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

How to achieve this?

Was it helpful?

Solution 3

With a flag to check which column is selected, this code works fine.

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

OTHER TIPS

I am adding an alternative answer as it answered the question that is asked by the title and may be what people are looking for if they come across this question.

The WinGrid will have one or more ColScrollRegions that give a scrollable region of headers and off of the ColScrollRegion there is a VisibleHeaders property that exposes the visible headers for the scroll region.

Note that this will provide the first visible column even if the grid is scrolled to the right and may not be the first column in the grid. When the scroll position of the scroll region is all the way to the left, then the first header in the VisibleHeadersCollection will return the first column in the grid.

The ColScrollRegions are accessed by the ColScrollRegions property on DisplayLayout and you can access the first visible header with:

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

If the header is a ColumnHeader, then it will expose the Column as a property.

EDIT: This code will get you the first visible Column.

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top