Double click list view

jpdbay

Active member
Joined
Feb 22, 2006
Messages
31
Programming Experience
Beginner
Dear all,

I hv a search form which loads search results when I click search button. Take note that the search form is used by all child forms in MDI application to display the results. The problem is when I double click a row in list view, I want the results to be populated in in the controls(text box, combo box,Date timePicker) of current active child form.

Can u anyone suggest me and shoe me sample code to solve the above prob?any queries, plz ask me. Looking foraward for your guys reply.

Rgds,
jpdbay
 
You should call the search form with ShowDialog. When the user double-clicks an item or presses the OK button you set the DialogResult to OK. You give the search form a property or properties that returns the data you want in whatever form is appropriate. When ShowDialog returns you test the return value and if it is OK then the caller retrieves the data from those properties and populates its own controls. Here's a simple example. Try creating a new project with two forms. Add a TextBox and a Button to Form1 and a Button to Form2, then add the following code:
VB.NET:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f As New Form2

        If f.ShowDialog() = Windows.Forms.DialogResult.OK Then
            'Retrieve the property from the dialogue.
            Me.TextBox1.Text = f.Var
        End If
    End Sub

End Class

Public Class Form2

    Private _var As String

    Public ReadOnly Property Var() As String
        Get
            Return Me._var
        End Get
    End Property

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me._var = "Hello World"
        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub

End Class
If you click the Button in Form1 and then the Button in Form2 you'll see that the string "Hello World" will end up in the TextBox in Form1.
 
Thanx Bro..The code explained well n I understand. but how do I populate the list view row results into the current active child form by double clicking it? The search form is common which is used by all child form to display search results. Below is of the the child form search button code:

VB.NET:
Private Sub btnSearchMRN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearchMRN.Click
 Dim oSearch As New frmSearch
        Dim sSQL As String

        sSQL = "SELECT id 'MRN ',p_name 'Name' FROM tbl_patient ORDER BY id"

        Try
           oSearch.FillDataset(sSQL)
            oSearch.Show()
        Catch
            oSearch.Dispose()
        End Try
End Sub
Plz help on this matter. Thank you

rgds,
jpdbay
 
Hi agn!

I dont understand how to create property(s) since each child form has diffrent number of controls whereas the search form is used by all of them. How to fic it? Please correct me if my statement is wrong. Please guide. Thnx.

Rgds,
jpdbay
 
Back
Top