shireenrao
Active member
Hello
I am creating listView in a procedure -
Dim lvi As ListViewItem
Create a new ListView control.
Dim listView1 As New ListView()
ListView1.Bounds = New Rectangle(New Point(10, 10), New Size(400, 200))
Set the view to show details.
ListView1.View = View.Details
Allow the user to edit item text.
ListView1.LabelEdit = True
Allow the user to rearrange columns.
ListView1.AllowColumnReorder = True
Select the item and subitems when selection is made.
listView1.FullRowSelect = True
Display grid lines.
listView1.GridLines = True
Sort the items in the list in ascending order.
listView1.Sorting = SortOrder.Ascending
listView1.Columns.Add("User Id", -2, HorizontalAlignment.Left)
listView1.Columns.Add("User Name", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Last Name", -2, HorizontalAlignment.Left)
listView1.Columns.Add("First Name", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Location", -2, HorizontalAlignment.Left)
Try
Dim myConnection As New OracleConnection(myConnString)
Dim myCommand As New OracleCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myReader As OracleDataReader
myReader = myCommand.ExecuteReader()
Dim strText As String
While myReader.Read
lvi = New ListViewItem()
lvi.Text = myReader("USER_ID")
lvi.SubItems.Add(myReader("USERNAME"))
lvi.SubItems.Add(myReader("LASTNAME"))
lvi.SubItems.Add(myReader("FIRSTNAME"))
lvi.SubItems.Add(myReader("LOCATION"))
listView1.Items.Add(lvi)
End While
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Add the ListView to the control collection.
Me.Controls.Add(ListView1)
Now when I try to use ListView1 from another function or procedure, I cant. I know why i cant.. its because Its not declared and is being created dynamically in the previous procedure. So when I created a listView on the form, and removed the new declaration from the procedure for the listview, I cant see the items I am adding properly. I just get one row, no columns, and the one row has two data from the first column.
What am I doing wrong.
Thank you in advance
I am creating listView in a procedure -
Dim lvi As ListViewItem
Create a new ListView control.
Dim listView1 As New ListView()
ListView1.Bounds = New Rectangle(New Point(10, 10), New Size(400, 200))
Set the view to show details.
ListView1.View = View.Details
Allow the user to edit item text.
ListView1.LabelEdit = True
Allow the user to rearrange columns.
ListView1.AllowColumnReorder = True
Select the item and subitems when selection is made.
listView1.FullRowSelect = True
Display grid lines.
listView1.GridLines = True
Sort the items in the list in ascending order.
listView1.Sorting = SortOrder.Ascending
listView1.Columns.Add("User Id", -2, HorizontalAlignment.Left)
listView1.Columns.Add("User Name", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Last Name", -2, HorizontalAlignment.Left)
listView1.Columns.Add("First Name", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Location", -2, HorizontalAlignment.Left)
Try
Dim myConnection As New OracleConnection(myConnString)
Dim myCommand As New OracleCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myReader As OracleDataReader
myReader = myCommand.ExecuteReader()
Dim strText As String
While myReader.Read
lvi = New ListViewItem()
lvi.Text = myReader("USER_ID")
lvi.SubItems.Add(myReader("USERNAME"))
lvi.SubItems.Add(myReader("LASTNAME"))
lvi.SubItems.Add(myReader("FIRSTNAME"))
lvi.SubItems.Add(myReader("LOCATION"))
listView1.Items.Add(lvi)
End While
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Add the ListView to the control collection.
Me.Controls.Add(ListView1)
Now when I try to use ListView1 from another function or procedure, I cant. I know why i cant.. its because Its not declared and is being created dynamically in the previous procedure. So when I created a listView on the form, and removed the new declaration from the procedure for the listview, I cant see the items I am adding properly. I just get one row, no columns, and the one row has two data from the first column.
What am I doing wrong.
Thank you in advance