Share via

How to load row data from listview or gridview

Vereato 20 Reputation points
2026-01-12T05:12:01.5533333+00:00

Hi there i would like to ask is if possible to load data from a row select.Item on Listview or Gridview and load on the player this is for Website and Winforms program both ways

here is the code any help

Imports System.Net
imports system.IO


Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Get the host name and assign it to the TextBox Text property
        Dim hostName As String = Dns.GetHostName()
        TextBox1.Text = hostName
	
	'Load Movies from Folder or Database
	LoadMoviesToList()
	
	
    End Sub
End Class
------------------------------------------------------------------------------------------
Private Sub LoadMoviesToList()

    ListView1.View = View.Details ' Ensure details view for columns
	ListView1.Columns.Add("ID", 20) ' ID is 2000
	ListView1.Columns.Add("#Code", 100) 'code of the movie is TT26545 
    ListView1.Columns.Add("Movie Title", 200) ' Cobra 1986
	ListView1.Columns.Add("Directory", 200)  X:/Movies/C/cobra.1986
    
	
    Dim sharePath As String ' Directory 
    Dim movieFiles() As String = IO.Directory.GetFiles(sharePath, "X:/Movies/C/Cobra.1986.mp4") ' Get Cobra Movie 

    For Each filePath As String In movieFiles
        Dim fileName As String = IO.Path.GetFileName(filePath)
        Dim lvi As New ListViewItem(fileName)
        ' Store the full path in the Tag property for easy access later
        lvi.Tag = filePath
        ListView1.Items.Add(lvi)
    Next
End Sub
----------------------------------------------------------------------------------------------------
Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged

    If ListView1.SelectedItems.Count > 0 Then
        Dim selectedItem As ListViewItem = ListView1.SelectedItems(0)
        Dim Code As String = CType(selectedItem.Code_Number, String) ' Get the Code

        ' Hostname and code  of the column read data 
        Dim hostName As String = GetLocalHostName()
        ' Example of here load movie using hostname and code: 
		'Dim fullPath As String = "http://192.168.xx.xx/Code=TT26545"

    
        ' Set the URL property of the Windows Media Player control to play the video
        AxWindowsMediaPlayer1.URL = fullPath
        ' The player should start automatically if AutoStart is True
    End If
End Sub

Developer technologies | VB
0 comments No comments

Answer accepted by question author
  1. Q&A Assist
    2026-01-12T05:12:15.3966667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To load data from a selected row in a ListView or GridView in your VB.NET application, you can use the SelectedIndexChanged event of the ListView control. In your provided code, you are already on the right track. Here’s how you can modify your ListView1_SelectedIndexChanged method to retrieve the necessary data and load it into the Windows Media Player control:

    1. Ensure that you store the relevant data (like Code and full path) in the Tag property of the ListViewItem when you create it.
    2. In the SelectedIndexChanged event, retrieve the data from the selected item and use it to set the URL of the media player.

    Here’s an updated version of your ListView1_SelectedIndexChanged method:

    Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
        If ListView1.SelectedItems.Count > 0 Then
            Dim selectedItem As ListViewItem = ListView1.SelectedItems(0)
            Dim fullPath As String = CType(selectedItem.Tag, String) ' Get the full path from the Tag property
            Dim code As String = selectedItem.SubItems(1).Text ' Assuming the Code is in the second column
    
            ' Example of constructing the URL using the hostname and code
            Dim hostName As String = GetLocalHostName()
            Dim fullUrl As String = "http://" & hostName & "/Code=" & code
    
            ' Set the URL property of the Windows Media Player control to play the video
            AxWindowsMediaPlayer1.URL = fullPath
            ' The player should start automatically if AutoStart is True
        End If
    End Sub
    

    Make sure that the Code is correctly referenced from the appropriate subitem index based on how you set up your ListView columns. In this example, I assumed that the Code is in the second column (index 1). Adjust the index as necessary based on your actual column setup.

    This approach will allow you to load the selected movie's data and play it in the media player when a row is selected in the ListView.


    References:

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.