Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > How to make the ListView items load a database row?
 

How to make the ListView items load a database row?

Can anyone tell me how to make the ListView items, that have been entered programmatically, load a database row?
TheQuietShadow  Monday, September 04, 2006 6:17 AM

I've got it, I found that this methood worked best for me. For anyone else with a similar problem, this is the fix. The code below gets the item that has been selected then matches the item to my database and displays the name of that person(DataRow)......

Private Sub EditButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditButton.Click

Me.Child_InformationTableAdapter.Fill(Me.Child_Information_DatabaseDataSet.Child_Information)

'Check which item has been selected'

Dim Count As Integer = Me.ListView1.Items.Count

Dim AddFromZero As Integer = 0

While AddFromZero < Count

If ListView1.Items(AddFromZero).Selected = True Then

Dim SelectedDataRow = Me.Child_Information_DatabaseDataSet.Child_Information.Rows(AddFromZero)("FirstName") + " " + Me.Child_Information_DatabaseDataSet.Child_Information.Rows(AddFromZero)("LastName")

MessageBox.Show(SelectedDataRow)

End If

AddFromZero = AddFromZero + 1

End While

End Sub

TheQuietShadow  Tuesday, September 05, 2006 6:40 AM
Ken Tucker  Monday, September 04, 2006 9:21 AM

Thank you, but this probably would not work for what I am doing. I need to find out how to utilize the ListView.SelectedItems component and connect the item to the database rowfrom which the item text has been coppied from. This is what I have so far.....

Child_Information_DatabaseDataSet.EnforceConstraints = False

Me.Child_InformationTableAdapter.Fill(Me.Child_Information_DatabaseDataSet.Child_Information)

For Each CurrentRow As DataRow In Me.Child_Information_DatabaseDataSet.Child_Information

Me.ListView1.Items.Add(CurrentRow.Item("FirstName") + " " + (CurrentRow.Item("LastName")), 0)

Next

TheQuietShadow  Monday, September 04, 2006 7:21 PM

I've got it, I found that this methood worked best for me. For anyone else with a similar problem, this is the fix. The code below gets the item that has been selected then matches the item to my database and displays the name of that person(DataRow)......

Private Sub EditButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditButton.Click

Me.Child_InformationTableAdapter.Fill(Me.Child_Information_DatabaseDataSet.Child_Information)

'Check which item has been selected'

Dim Count As Integer = Me.ListView1.Items.Count

Dim AddFromZero As Integer = 0

While AddFromZero < Count

If ListView1.Items(AddFromZero).Selected = True Then

Dim SelectedDataRow = Me.Child_Information_DatabaseDataSet.Child_Information.Rows(AddFromZero)("FirstName") + " " + Me.Child_Information_DatabaseDataSet.Child_Information.Rows(AddFromZero)("LastName")

MessageBox.Show(SelectedDataRow)

End If

AddFromZero = AddFromZero + 1

End While

End Sub

TheQuietShadow  Tuesday, September 05, 2006 6:40 AM

You can use google to search for other answers

Custom Search

More Threads

• Data type Yes/No
• My namespace not working in VS 2005 SqlServer projects
• Datagridviewcombobox data do not update the cell
• Convert C# to VB 2005 - Problem using inpout32.dll
• Problem regarding toolbar item?
• nextinstance
• 'SyncLock Me' within a DLL
• C# fixed to VB
• First time converting Com objects
• How do you prevent multiple users colliding on a single record?