Question

I have to get the column number in the grid.

Eg: If i have Name,Age,Number as three columns in the grid and i give the headertext(Age) of the column it should return the Number(2) which represents the Age is 2nd column of the grid.

For Each UltraGridColumn In Me.TransactionsGrid.Rows.Band.Columns
    If (UltraGridColumn.Hidden = False) Then
        'UltraGridColumn.Header.Caption
        'Get the cell
         UltraGridCell = UltraGridRow.Cells("Number Here")
    End If
Next

Now here i have to get the column number which is not hidden. I have the headertext of the column and i need the number.

How can i achieve that?

Was it helpful?

Solution

Every UltraGridColumn has a property called Index that is the index of the column in the band's column collection. So if you want to search a column using the header text you could write this

For Each col In Me.TransactionsGrid.Rows.Band.Columns
     If (col.Hidden = False) Then
         if col.Header.Caption = searchedHeaderText Then
              grid.ActiveRow.Cells(col).Value = col.Index.ToString()
         End If
     End If
Next

What do you really want to do with the Index information is not very clear from your questio, so I have used this info to set the value of the ActiveRow in the cell corrisponding to the column searched. Add more info to your question is this is not what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top