[RESOLVED] Getting Data from listView
Hi i currently have a listview on my form that is set to "details" view and is popoulated by a table in my sql database.
what i want to be able to do is when i double click on a selected row i want all the details in that row to appear in another form so that i can edit them.
how do i populate the edit form with the data from the selected row i am double clicking on?
can anyone help me?
Thanks Roofuss
Re: Getting Data from listView
is your listview multiselect?
Re: Getting Data from listView
No its note not multi select just full row select
Re: Getting Data from listView
if not multiselect, try this:
vb Code:
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
MsgBox(ListView1.Items(ListView1.SelectedIndices(0)).SubItems(1).Text) 'gets text from second column
End Sub
Re: Getting Data from listView
no sorry that doesnt work and it only brings the 1st column up in a message box i need to be able to display the data in my edit form which is called frmCreateTask
the code i have at the moment is as follows:
vb Code:
Private Sub lvTasks_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvTasks.DoubleClick
Dim Row As DataRow = lvTasks.Items(lvTasks.SelectedItems).Row
Using dialogue As New frmCreateTask(Row)
dialogue.ShowDialog()
End Using
End Sub
but causes an overload resolution
any ideas?
thanks
Re: Getting Data from listView
ok. try this:
vb Code:
Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
Dim lvi As ListViewItem = ListView1.Items(ListView1.SelectedIndices(0))
Dim frm As New frmCreateTask(lvi)
frm.Show()
End Sub
frmCreateTask should have a sufficient number of textboxes, named Textbox1, Textbox2, etc:
vb Code:
Public Class frmCreateTask
Public Sub New(ByVal lvi As ListViewItem)
InitializeComponent()
For x As Integer = 1 To lvi.SubItems.Count
Me.Controls("textbox" & x.ToString).Text = lvi.SubItems(x - 1).Text
Next
End Sub
End Class
Re: Getting Data from listView
i think we're getting there but now i get a run time error that says
"Object reference not set to an instance of an object." at the highlighted area
[HEIGHLIGHT] Public Sub New(ByVal lvi As ListViewItem)
InitializeComponent()
For x As Integer = 1 To lvi.SubItems.Count
Me.Controls("textbox" & x.ToString).Text = lvi.SubItems(x - 1).Text
Next
End Sub
[/HEIGHLIGHT]
Re: Getting Data from listView
how many subitems are there? do you have that many textboxes on the form (frmCreateTask)? are they named textbox1, textbox2, etc?
Re: Getting Data from listView
I have got 6 sub items in total and on frmCreateTask i have 6 textboxes and one drop down box. they are all labelled with reference to what they to but to make it easier and faster we can just use textbox1, textbox2 etc.. if you like?
Thanks
Re: Getting Data from listView
you could just type them out instead of using a loop:
txtWhatever.text = lvi.subitems(0).text
'etc
Re: Getting Data from listView
At 6:00 in the morning you are offically my hero. thats worked great !!!
thanks for all your help