listview - selected row

  • Thread starter Thread starter DotNetJunkies User
  • Start date Start date
D

DotNetJunkies User

Hi there :)
Im new to dot net and need help with a listview. Well, i have a listview in place on my form displaying data, but what i'd like to do next is enable the user to double click on a selected row, which will open up a new form, displaying the row information. I dont know how to do this... from double clicking on a selected row thru to displaying data on new form...any help would be much appreciated. Thanks.
 
* DotNetJunkies User said:
Im new to dot net and need help with a listview. Well, i have a listview in place on my form displaying data, but what i'd like to do next is enable the user to double click on a selected row, which will open up a new form, displaying the row information. I dont know how to do this... from double clicking on a selected row thru to displaying data on new form...any help would be much appreciated. Thanks.

What's the problem? Handling the double click? Passing the data
to/from the dialog?
 
DotNetJunkies User said:
Hi there :)
Im new to dot net and need help with a listview. Well,
i have a listview in place on my form displaying data,
but what i'd like to do next is enable the user to double
click on a selected row, which will open up a new form,
displaying the row information. I dont know how to do
this... from double clicking on a selected row thru to
displaying data on new form...any help would be much
appreciated. Thanks.

The good news is, it's pretty easy. The bad news is, well there isn't
really any bad news. What language are you using? I'll give a VB example.

Figuring out which row the user double-clicked on is possible, but not
trivial. Fortunately, the ListView class is one step ahead of you, and has
an event called ItemActivate that will be raised when the user double-clicks
on a row (or presses enter on that row; I hope that's not a problem for
you). In that event, you can open your new form. For example:

Private Sub ListView1_ItemActivate(sender As Object, e As EventArgs) _
Handles ListView1.ItemActivate

' Open your form and set a property on it to the selected item's text
Dim editForm As MyForm = New MyForm
editForm.Property1 = Me.SelectedItems(0).Text
editForm.ShowDialog(Me)
End Sub

As a side note, the ListView class has a property called Activation that
controls whether a single or double click is required to activate the
selected item. Double-clicking is the default.

Hope this helps!
Jeremy
 
Listview has a double click event...

Private Sub ListViewLookup_DoubleClick(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ListViewLookup.DoubleClick

objListViewItem = ListViewLookup.SelectedItems.Item(0)

End Sub

HTH
Charlie
 
Back
Top