This is a migrated thread and some comments may be shown as answers.

Problem hiding column depending on another column's value

1 Answer 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve Newbery
Top achievements
Rank 1
Steve Newbery asked on 06 Dec 2008, 01:46 PM
I have a radGrid with a three level hierarchy. The second level has a command button, which is hidden depending on the value of a column. This works well except when the third level is expanded, and the buttons that should be hidden become visible.

The idea is to hide the Edit and Delete buttons if the status of an order is Cancelled.

The code to hide the buttons is:

    Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs)  
        '-----------------------------------------------------------------------  
        ' In the grid, hide the cancel button if the order is not open  
        '-----------------------------------------------------------------------  
        If "Orders".Equals(e.Item.OwnerTableView.Name) Then  
 
            If TypeOf e.Item Is GridDataItem AndAlso Not e.Item.IsInEditMode Then  
                Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)  
                Dim Status As String = dataItem("OrderStatus").Text  
                  
                If Status <> "O" Then  
                    ' Just replace the cell contents with a space. We do this because  
                    ' if we make the column invisible, the grid lines disappear too.  
                    dataItem("OrderCancelColumn").Text = "&nbsp;" 
                End If  
            End If  
        End If  
 
    End Sub  
 

When the third level of the hierarchy is expanded, ie to show the order details, there seems to be no ItemDataBound event for the second level, so this code isn't executed and the OrderCancelColumn is always visible.

The behaviour is different depending on the HierarchyLoadMode. It has to be ServerOnDemand - the performance is too bad when it is Client.

Can anyoneplease help? Maybe there's a better way to do what we want?

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Dec 2008, 08:47 AM
Hi Steve,

One suggestion will be to access the  parent item (from the second level) on Expanding the third Level and set the desired functionality again.

VB:
 
 
     Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) 
         
         If "Orders".Equals(e.Item.OwnerTableView.Name) Then 
             test(e) 
         ElseIf "Detail2".Equals(e.Item.OwnerTableView.Name) Then 
             Dim parentItem As GridDataItem = DirectCast(e.Item.OwnerTableView.ParentItem, GridDataItem) 
             If "Orders".Equals(parentItem.OwnerTableView.Name) Then 
                 test(e) 
             End If 
             
             
         End If 
         
         
     End Sub 
     
     Private Shared Sub test(ByVal e As GridItemEventArgs) 
         If TypeOf e.Item Is GridDataItem AndAlso Not e.Item.IsInEditMode Then 
             Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem) 
             'string Status = dataItem["OrderStatus"].Text; 
             If Status <> "0" Then 
                 ' Just replace the cell contents with a space. We do this because 
                 ' if we make the column invisible, the grid lines disappear too. dataItem("OrderCancelColumn").Text = "&nbsp;"
             End If 
         End If 
     End Sub 
 
 

note: Detail2 is the Name of  the third level table.

Thanks
Princy
Tags
Grid
Asked by
Steve Newbery
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or