Infragistics 2005 UltraGrid problem with hiding/showing primary key column

Posts   
 
    
imagina
User
Posts: 3
Joined: 08-Aug-2005
# Posted on: 08-Aug-2005 12:52:54   

I am using UltraGrid of Infragistics 2005 with LLBLGen adapter. Using predefine data cloumn binding to select a specific column to show on grid by following code

With Northwind DB bind 3 columns from Customers table (CustomerID,CompanyName, Country) ... Dim UltraGridBand1 As Infragistics.Win.UltraWinGrid.UltraGridBand = New Infragistics.Win.UltraWinGrid.UltraGridBand("Customers", -1) Dim UltraGridColumn1 As Infragistics.Win.UltraWinGrid.UltraGridColumn = New Infragistics.Win.UltraWinGrid.UltraGridColumn("CustomerID") Dim UltraGridColumn2 As Infragistics.Win.UltraWinGrid.UltraGridColumn = New Infragistics.Win.UltraWinGrid.UltraGridColumn("CompanyName") Dim UltraGridColumn3 As Infragistics.Win.UltraWinGrid.UltraGridColumn = New Infragistics.Win.UltraWinGrid.UltraGridColumn("Country") ...

... UltraGridColumn1.Header.VisiblePosition = 0 UltraGridColumn2.Header.VisiblePosition = 1 UltraGridColumn3.Header.VisiblePosition = 2 UltraGridBand1.Columns.AddRange(New Object() {UltraGridColumn1, UltraGridColumn2, UltraGridColumn3}) Me.UltraGrid1.DisplayLayout.BandsSerializer.Add(UltraGridBand1) Me.UltraGrid1.DisplayLayout.MaxBandDepth = 1 ... Dim adapter As New DataAccessAdapter Dim mCustomer As New EntityCollection(New CustomersEntityFactory) adapter.FetchEntityCollection(mCustomer, Nothing)

    'Me.UltraGrid1.DataSource = mCustomer
    UltraGrid1.SetDataBinding(mCustomer, Nothing, True)
    DataGrid1.DataSource = mCustomer

After finishing binding the UltraGrid the column CustomerID is hidden in UltraGrid. I need to show this column. (CustomerID is primary key) but do not know to it.

I can access the column value, with this snippet I can see that CustomerID ... Dim row As Infragistics.Win.UltraWinGrid.UltraGridRow Dim id As String

    row = UltraGrid1.ActiveRow

    If Not row Is Nothing Then
        id = row.Cells("CustomerID").Text()
        MsgBox(id)
    End If

... Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39885
Joined: 17-Aug-2003
# Posted on: 08-Aug-2005 19:20:25   

I don't have the ultragrid v2005 here, so I can't try to reproduce it. It might be the grid hides readonly columns (is that a setting in taht grid?) the column should show up normally...

Frans Bouma | Lead developer LLBLGen Pro
jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 08-Aug-2005 19:36:04   

imagina wrote:

I am using UltraGrid of Infragistics 2005 with LLBLGen adapter. Using predefine data cloumn binding to select a specific column to show on grid by following code

With Northwind DB bind 3 columns from Customers table (CustomerID,CompanyName, Country) ... Dim UltraGridBand1 As Infragistics.Win.UltraWinGrid.UltraGridBand = New Infragistics.Win.UltraWinGrid.UltraGridBand("Customers", -1) Dim UltraGridColumn1 As Infragistics.Win.UltraWinGrid.UltraGridColumn = New Infragistics.Win.UltraWinGrid.UltraGridColumn("CustomerID") Dim UltraGridColumn2 As Infragistics.Win.UltraWinGrid.UltraGridColumn = New Infragistics.Win.UltraWinGrid.UltraGridColumn("CompanyName") Dim UltraGridColumn3 As Infragistics.Win.UltraWinGrid.UltraGridColumn = New Infragistics.Win.UltraWinGrid.UltraGridColumn("Country") ...

... UltraGridColumn1.Header.VisiblePosition = 0 UltraGridColumn2.Header.VisiblePosition = 1 UltraGridColumn3.Header.VisiblePosition = 2 UltraGridBand1.Columns.AddRange(New Object() {UltraGridColumn1, UltraGridColumn2, UltraGridColumn3}) Me.UltraGrid1.DisplayLayout.BandsSerializer.Add(UltraGridBand1) Me.UltraGrid1.DisplayLayout.MaxBandDepth = 1 ... Dim adapter As New DataAccessAdapter Dim mCustomer As New EntityCollection(New CustomersEntityFactory) adapter.FetchEntityCollection(mCustomer, Nothing)

    'Me.UltraGrid1.DataSource = mCustomer
    UltraGrid1.SetDataBinding(mCustomer, Nothing, True)
    DataGrid1.DataSource = mCustomer

After finishing binding the UltraGrid the column CustomerID is hidden in UltraGrid. I need to show this column. (CustomerID is primary key) but do not know to it.

I can access the column value, with this snippet I can see that CustomerID ... Dim row As Infragistics.Win.UltraWinGrid.UltraGridRow Dim id As String

    row = UltraGrid1.ActiveRow

    If Not row Is Nothing Then
        id = row.Cells("CustomerID").Text()
        MsgBox(id)
    End If

... Thanks.

Have you tried:


UltraGrid1.DisplayLayout.Bands(0).Columns("CustomerID").Hidden = False

simple_smile

Jeff...

Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 08-Aug-2005 21:23:40   

I use that grid all the time and have not had a problem like you described. But, I don't bind to it the same way you do. You may want to give this a shot.

In you InitializeLayout, add the following:

        Dim Cols() As String = {EntityFieldFactory.Create(AssignmentFieldIndex.DueDate).Name, _
        EntityFieldFactory.Create(AssignmentFieldIndex.Name).Name, _
        EntityFieldFactory.Create(AssignmentFieldIndex.Weight).Name, _
        EntityFieldFactory.Create(AssignmentFieldIndex.RequiredFlag).Name, _
        EntityFieldFactory.Create(AssignmentFieldIndex.SummarizeFlag).Name, _
        EntityFieldFactory.Create(AssignmentFieldIndex.CimWorkSampleFlag).Name, _
        EntityFieldFactory.Create(AssignmentFieldIndex.PublishPALAssignment).Name}


        uiHelper.ShowCols(grdExistingAssignments.DisplayLayout.Bands(0), Cols, Activation.ActivateOnly)

The Cols table defines what items you want to see in the grid and the order of those items. The code for ShowCols is

    Public Shared Sub ShowCols(ByRef band As UltraGridBand, ByVal colsToShow() As String, _
        ByVal cellActivation As Activation)

        Dim Col As UltraGridColumn
        Dim Position As Integer
        Dim ColKey As String
        Dim Count As Integer

        ' Hide all columns except ones in colsToShow.
        For Each Col In band.Columns
            Position = Array.IndexOf(colsToShow, Col.Key)
            If Position = -1 Then
                Col.Hidden = True
            Else
                Col.CellActivation = cellActivation
            End If
        Next

        ' Change column position to match the same as colsToShow.

        Try
            For Each ColKey In colsToShow
                band.Columns(ColKey).Header.VisiblePosition = Count
                Count += 1
            Next

        Catch ex As Exception
        End Try

    End Sub


Take care,

Fishy

imagina
User
Posts: 3
Joined: 08-Aug-2005
# Posted on: 09-Aug-2005 12:01:37   

Thanks Fishy, this works for me but another question how to set the header caption of the grid?

Thanks.

PS Jeff, I tried your code before and it did not work.

Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 09-Aug-2005 16:12:48   

imagina wrote:

Thanks Fishy, this works for me but another question how to set the header caption of the grid?

        With grdExistingAssignments.DisplayLayout.Bands(0)
            .Columns(EntityFieldFactory.Create(AssignmentFieldIndex.DueDate).Name()).Header.Caption = "Due Date"
            .Columns(EntityFieldFactory.Create(AssignmentFieldIndex.RequiredFlag).Name()).Header.Caption = "Required"
            .Columns(EntityFieldFactory.Create(AssignmentFieldIndex.SummarizeFlag).Name()).Header.Caption = "Summarize"
            .Columns(EntityFieldFactory.Create(AssignmentFieldIndex.CimWorkSampleFlag).Name()).Header.Caption = "Work Sample"
            .Columns(EntityFieldFactory.Create(AssignmentFieldIndex.PublishPALAssignment).Name()).Header.Caption = "PAL"
            .Columns(EntityFieldFactory.Create(AssignmentFieldIndex.Name).Name()).MinWidth = 200
            .Columns(EntityFieldFactory.Create(AssignmentFieldIndex.DueDate).Name()).MinWidth = 50
            .Columns(EntityFieldFactory.Create(AssignmentFieldIndex.DueDate).Name()).MaxWidth = 50
            '.Columns(EntityFieldFactory.Create(AssignmentFieldIndex.Name).Name()).MaxWidth = 200
        End With

stuck_out_tongue_winking_eye

imagina
User
Posts: 3
Joined: 08-Aug-2005
# Posted on: 10-Aug-2005 13:26:05   

Thanks Fishy. Your solution works very great exceps it is very programmatic. But it works. Who cares? You are really the Infragistics guy. Ha ha... Thanks.

Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 10-Aug-2005 16:10:30   

imagina wrote:

Your solution works very great exceps it is very programmatic.

Ah, yes, but there lies the beauty. If you remove an element from your table then your program will no longer compile, let alone run. sunglasses