Back to Browse

VB.NET S1E4 : DataGridView - Fill From a HashSet

230 views
May 3, 2018
10:24

SOURCE CODE REFERENCE : http://camposha.info/vb-net/datagridview-hashset A HashSet is generic collection that represents a set of values. While a datagridview is windows froms components that displays items in a customized grid. A HashSet is defined in the `System.Colletions.Generic` namespace and is generic. In this class we see how to work with both, with the hashset being our component. The HashSet is our data source and we want to read its data and populate a datagridview. We create a subroutine called `populateData` that does that for us: ```vb Private Sub populateData() Dim nebulae As HashSet(Of String) = New HashSet(Of String) From {"Horse Head", "Black Widow", "Ghost Head", "Cat's Eye", "Elephant's Trunk", "Helix", "Rosette", "Snake", "Bernad 68", "Ant", "Orion", "Butterfly", "Eagle", "Own", "Ring", "Pelican", "Cone", "Flame", "Witch Head", "Bumerang"} Dim nebularCategory As HashSet(Of String) = New HashSet(Of String) From {"HII REGION ", "REFLECTION NEBULAR", "PLANETARY NEBULAR", "SUPERNOVA REMNANTS", "DARK NEBULAR"} Dim r As Random = New Random() For Each nebular As String In nebulae myDataGridView.Rows.Add(nebular, nebularCategory.ToArray()(r.[Next](0, 5)), (r.[Next](9, 9999)).ToString()) Next End Sub ``` We then get the item that's been clicked and show in a messagebox: Let's go.

Download

0 formats

No download links available.

VB.NET S1E4 : DataGridView - Fill From a HashSet | NatokHD