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?
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
ItemCreated or ItemDataBound, if you loop the Items-property those are omitted by default.