Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
470
Databound columns not showing
posted

Hi,

I'm binding to a WebDataGrid but can't seem to hide the columns because after the bind they aren't available in the collection.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Dim o As New clsFitter
            clsMySQL.Conns.LoadConnections()
            clsMySQL.CurrentUser = New clsUser
            clsMySQL.CurrentUser.LoadUser(5)
            dgCurrent.DataSource = o.GetCurrentJobs
            LoadTheseColumns(dgCurrent, "JobRef(Job #),Address(Address)")
        End If
    End Sub
    Private Sub LoadTheseColumns(ByRef dg As GridControls.WebDataGrid, ByVal sColumns As String)
        Dim iCol As Integer
        Dim ColumnName, ColumnHeader As String
        Dim arrColumn() As String

        For Each col As GridControls.GridField In dg.Columns
            col.Hidden = True
        Next
        For Each col As GridControls.GridField In dg.Columns
            arrColumn = Split(sColumns, ",")
            For iCol = 0 To arrColumn.GetUpperBound(0)
                If InStr(arrColumn(iCol), "(", CompareMethod.Text) > 0 Then
                    ColumnName = Mid(arrColumn(iCol), 1, InStr(arrColumn(iCol), "(", CompareMethod.Text) - 1)
                    Dim iStart, iLen As Integer
                    iStart = InStr(arrColumn(iCol), "(", CompareMethod.Text) + 1
                    iLen = Len(arrColumn(iCol))
                    ColumnHeader = Mid(arrColumn(iCol), iStart, iLen - iStart)
                Else
                    ColumnName = arrColumn(iCol)
                    ColumnHeader = arrColumn(iCol)
                End If
                dg.Columns(ColumnName).Hidden = False
                dg.Columns(ColumnName).Header.Text = ColumnHeader
                dg.Columns(ColumnName).VisibleIndex = iCol
            Next
        Next
    End Sub

 

In the code above when I get to dg.Columns the count is zero.  When the page displays all columns are however shown.  I've also tried the above referring to dgCurrent(the grid) directly rather than byref.  Also with AutoGenerateColumns true and false...

The grid.rows.count is 44 so the data is being loaded.

Am I missing something obvious??

Thanks