JayBeeOH

DataGridView with ArrayList

May 1st, 2015
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.09 KB | None | 0 0
  1. '------------------------------------------------------------------------------------------
  2. '           Notice of My Copyright and Intellectual Property Rights
  3. '
  4. ' Any intellectual property contained within the program by Joseph L. Bolen remains the
  5. ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
  6. ' publish or provide such intellectual property to any other person or entity for any
  7. ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
  8. '
  9. '                 Copyright © 2015. All rights reserved.
  10. '        All trademarks remain the property of their respective owners.
  11. '-------------------------------------------------------------------------------------------
  12. ' Program Name:   DataGridView with ArrayList
  13. '
  14. ' Author:         Joseph L. Bolen
  15. ' Date Created:   May 2015
  16. '
  17. ' Description:    Use ArrayList for DataSource for DataGridView.
  18. '
  19. '                 Documentation is at:
  20. '                   App's Visual Basic .NET code is at http://pastebin.com/aFzzjXLA
  21.  
  22. '-------------------------------------------------------------------------------------------
  23.  
  24.  
  25. Public Class MainForm
  26.  
  27.     Private myArrayList As New ArrayList()
  28.     Private currencyMgmr As CurrencyManager
  29.  
  30.     Private Sub MainForm_Load(sender As Object, e As EventArgs) _
  31.         Handles MyBase.Load
  32.  
  33.         With myArrayList
  34.             .Add(New Contributers("USA", "Joe", "Bolen"))
  35.             .Add(New Contributers("India", "Vinod", "Kc"))
  36.             .Add(New Contributers("USA", "Michael", "Corbett"))
  37.         End With
  38.  
  39.         With DataGridView1
  40.             .DataSource = myArrayList
  41.             .Columns("Country").Visible = False
  42.             .Columns("FirstName").HeaderText = "First Name"
  43.             .Columns("LastName").HeaderText = "Last Name"
  44.             .SelectionMode = DataGridViewSelectionMode.FullRowSelect
  45.             .MultiSelect = False
  46.         End With
  47.  
  48.         currencyMgmr = CType(DataGridView1.BindingContext(myArrayList), CurrencyManager)
  49.     End Sub
  50.  
  51. #Region " Navigation"
  52.  
  53.     Private Sub FirstButton_Click(sender As Object, e As EventArgs) _
  54.         Handles FirstButton.Click
  55.  
  56.         currencyMgmr.Position = 0
  57.     End Sub
  58.  
  59.     Private Sub PreviousButton_Click(sender As Object, e As EventArgs) _
  60.         Handles PreviousButton.Click
  61.  
  62.         currencyMgmr.Position -= 1
  63.     End Sub
  64.  
  65.     Private Sub NextButton_Click(sender As Object, e As EventArgs) _
  66.         Handles NextButton.Click
  67.  
  68.         currencyMgmr.Position += 1
  69.     End Sub
  70.  
  71.     Private Sub LastButton_Click(sender As Object, e As EventArgs) _
  72.         Handles LastButton.Click
  73.  
  74.         currencyMgmr.Position = myArrayList.Count - 1
  75.     End Sub
  76.  
  77. #End Region
  78.  
  79. End Class
  80.  
  81. Public Class Contributers
  82.  
  83.     Public Property Country As String
  84.     Public Property FirstName As String
  85.     Public Property LastName As String
  86.  
  87.     Sub New(ByVal countryParm As String, ByVal firstNameParm As String, ByVal lastNameParm As String)
  88.         Country = countryParm
  89.         FirstName = firstNameParm
  90.         LastName = lastNameParm
  91.     End Sub
  92.  
  93. End Class
Advertisement
Add Comment
Please, Sign In to add comment