vivek_nz76
Member
- Joined
- Sep 20, 2005
- Messages
- 8
- Programming Experience
- 3-5
Fails saying that Object reference not set
The code:
Public Class User
Inherits System.Windows.Forms.Form
Dim userCol As CDbUsers
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
userCol = New CDbUsers
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lvwUser As System.Windows.Forms.ListView
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.lvwUser = New System.Windows.Forms.ListView
Me.SuspendLayout()
'
'lvwUser
'
Me.lvwUser.Location = New System.Drawing.Point(8, 8)
Me.lvwUser.Name = "lvwUser"
Me.lvwUser.Size = New System.Drawing.Size(592, 224)
Me.lvwUser.TabIndex = 0
'
'User
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(616, 273)
Me.Controls.Add(Me.lvwUser)
Me.Name = "User"
Me.Text = "User"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub User_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oUser As New CData
Dim _User As New CUser
'Header
Call HeaderlvwUser(lvwUser)
'Populating the Collection
userCol = oUser.GetUserDetail()
For Each _User In userCol --FAILS HERE
Call AddItemToListView(_User)
Next
End Sub
Private Sub HeaderlvwUser(ByVal lvwListView As ListView)
With lvwListView
.HeaderStyle = ColumnHeaderStyle.Clickable
.View = View.Details
'Clearing any existing list
.Items.Clear()
.MultiSelect = False
'Add the column headers
.Columns.Add("UserID", 20, HorizontalAlignment.Center)
.Columns.Add("First Name", 100, HorizontalAlignment.Center)
.Columns.Add("Last Name", 100, HorizontalAlignment.Center)
.Columns.Add("Username", 100, HorizontalAlignment.Center)
.Columns.Add("Password", 100, HorizontalAlignment.Center)
.Sorting = SortOrder.Ascending
End With
End Sub
Private Sub AddItemToListView(ByVal oUser As CUser, Optional ByVal bSelectItem As Boolean = False)
Dim lvwItem As ListViewItem
lvwItem = lvwUser.Items.Add(oUser.UserID)
lvwItem.SubItems.Add(oUser.FName)
lvwItem.SubItems.Add(oUser.LName)
lvwItem.SubItems.Add(oUser.Username)
lvwItem.SubItems.Add(oUser.Password)
End Sub
End Class
The code:
Public Class User
Inherits System.Windows.Forms.Form
Dim userCol As CDbUsers
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
userCol = New CDbUsers
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lvwUser As System.Windows.Forms.ListView
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.lvwUser = New System.Windows.Forms.ListView
Me.SuspendLayout()
'
'lvwUser
'
Me.lvwUser.Location = New System.Drawing.Point(8, 8)
Me.lvwUser.Name = "lvwUser"
Me.lvwUser.Size = New System.Drawing.Size(592, 224)
Me.lvwUser.TabIndex = 0
'
'User
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(616, 273)
Me.Controls.Add(Me.lvwUser)
Me.Name = "User"
Me.Text = "User"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub User_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oUser As New CData
Dim _User As New CUser
'Header
Call HeaderlvwUser(lvwUser)
'Populating the Collection
userCol = oUser.GetUserDetail()
For Each _User In userCol --FAILS HERE
Call AddItemToListView(_User)
Next
End Sub
Private Sub HeaderlvwUser(ByVal lvwListView As ListView)
With lvwListView
.HeaderStyle = ColumnHeaderStyle.Clickable
.View = View.Details
'Clearing any existing list
.Items.Clear()
.MultiSelect = False
'Add the column headers
.Columns.Add("UserID", 20, HorizontalAlignment.Center)
.Columns.Add("First Name", 100, HorizontalAlignment.Center)
.Columns.Add("Last Name", 100, HorizontalAlignment.Center)
.Columns.Add("Username", 100, HorizontalAlignment.Center)
.Columns.Add("Password", 100, HorizontalAlignment.Center)
.Sorting = SortOrder.Ascending
End With
End Sub
Private Sub AddItemToListView(ByVal oUser As CUser, Optional ByVal bSelectItem As Boolean = False)
Dim lvwItem As ListViewItem
lvwItem = lvwUser.Items.Add(oUser.UserID)
lvwItem.SubItems.Add(oUser.FName)
lvwItem.SubItems.Add(oUser.LName)
lvwItem.SubItems.Add(oUser.Username)
lvwItem.SubItems.Add(oUser.Password)
End Sub
End Class