|
-
Jul 4th, 2009, 10:33 AM
#1
Thread Starter
Lively Member
[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
-
Jul 4th, 2009, 10:53 AM
#2
Re: Getting Data from listView
is your listview multiselect?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 4th, 2009, 10:55 AM
#3
Thread Starter
Lively Member
Re: Getting Data from listView
No its note not multi select just full row select
-
Jul 4th, 2009, 11:00 AM
#4
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 4th, 2009, 11:10 AM
#5
Thread Starter
Lively Member
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
-
Jul 4th, 2009, 11:22 AM
#6
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 4th, 2009, 01:07 PM
#7
Thread Starter
Lively Member
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]
-
Jul 4th, 2009, 02:48 PM
#8
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?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 4th, 2009, 11:48 PM
#9
Thread Starter
Lively Member
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
-
Jul 4th, 2009, 11:50 PM
#10
Re: Getting Data from listView
you could just type them out instead of using a loop:
txtWhatever.text = lvi.subitems(0).text
'etc
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 5th, 2009, 12:01 AM
#11
Thread Starter
Lively Member
Re: Getting Data from listView
At 6:00 in the morning you are offically my hero. thats worked great !!!
thanks for all your help
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|