0

I was able to hide my unwanted column and rows in my DataGrid using OnItemDataBound

 e.Item.Cells(0).Visible = False

but the problem is the Headers are also disappearing. How can i hide the rows only and remain its header visible?

1 Answer 1

2

You have to check the DataGridItem.ItemType and only apply the code if it's Item or AlternatingItem to skip the Header:

Sub Item_Bound(sender As Object, e As DataGridItemEventArgs) 
      If e.Item.ItemType = ListItemType.Item OrElse _
            e.Item.ItemType = ListItemType.AlternatingItem Then
        e.Item.Cells(0).Visible = False
     End If         
End Sub

As an aside, if you loop all Items in the grid all other ItemTypes are skipped automatically.

For Each item As DataGridItem In dataGrid1.Items
    ' Here only Item/AlternatingItem items are available,  others are omitted by default.
Next
Sign up to request clarification or add additional context in comments.

2 Comments

whoa, been searchin answers for days, i didn't know i can do it like this. thank you @Tim!.
@dale: note that i've edited my answer to mention that the header,footer are only passed to ItemCreated or ItemDataBound, if you loop the Items-property those are omitted by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.