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 ItemType
s are skipped automatically.
For Each item As DataGridItem In dataGrid1.Items
' Here only Item/AlternatingItem items are available, others are omitted by default.
Next
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.