chlade
asked on
calling a subform passing data
I have a question that should be simple, but has me stumped. I can probably find an ugly way to do this, but it seems to be something that should be able to be handled in a straightforward way.
I have a form with a listview control. When the user doubleclicks a row, I want to call a separate form where the user can edit the various fields that make up the record the user clicked on the first form.
I have no problem with the handling of the listview and so on. My question is simply: How do I open another form, populating fields with data from the first form?
As a side question (but still related), I have an imagelist on the first form. I would like to refer to the same images on my second form. Is it better to recreate the imagelist (I'd think not), refer back to the original form, or pass the image list to the second form? How would I go about doing this?
Thanks,
Chris
I have a form with a listview control. When the user doubleclicks a row, I want to call a separate form where the user can edit the various fields that make up the record the user clicked on the first form.
I have no problem with the handling of the listview and so on. My question is simply: How do I open another form, populating fields with data from the first form?
As a side question (but still related), I have an imagelist on the first form. I would like to refer to the same images on my second form. Is it better to recreate the imagelist (I'd think not), refer back to the original form, or pass the image list to the second form? How would I go about doing this?
Thanks,
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I haven't forgot about this question but I got pulled off onto a different project and probably won't get back to this for a week or two.
ASKER
Thanks natloz, but that didn't help me a lot. It may work, but it was a little too much code for me to make sense of.
The second response was exactly what I needed. Thanks.
The second response was exactly what I needed. Thanks.
You may be able to help me on this one. Kinda sounds like the same thing. But I am not too sure.
https://www.experts-exchange.com/questions/21257743/Pass-Datagrid-Value-to-a-form.html
https://www.experts-exchange.com/questions/21257743/Pass-Datagrid-Value-to-a-form.html
'*************************
'User wants to edit an AFE Detail
'*************************
Private Sub btnEditItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditItem.Click
Dim bFail As Boolean = False
Dim oDs As New DataSet("dsAFE") 'Dataset object
Dim cDB As clsDBConn = New clsDBConn 'Connection Class
Dim strConn As String = cDB.getStrConn 'Get connection string for database
Dim oConn As New SqlConnection 'SQL connection object
Dim oComm As SqlCommand 'SQL Command object
'Connect to SQL server and validate login
Try
'Pass connection string to SqlConnection
oConn.ConnectionString = strConn
'*************************
'Load the AFE Detail Table
'*************************
'SQL Database statements
oComm = New SqlCommand
oComm.CommandType = CommandType.StoredProcedur
oComm.CommandText = "spGetAFEDetail"
oComm.Connection = oConn
'Send in parameters
oComm.Parameters.Add(New SqlParameter("@pkAFEDetail
'create and fill the Data Adapter
Dim oDa As New SqlDataAdapter(oComm) 'SQL Data Adapter object
oDa.Fill(oDs, "tblAFEDetail")
Catch
MsgBox("Error connecting to SQL Server")
End Try
If dgAFEDetailGrid.VisibleRow
MsgBox("No AFE Detail is selected in the Grid.")
Else
Me.Cursor = System.Windows.Forms.Curso
Dim oSelectedCell As DataGridCell
Dim oSelectedItem As Object
Dim intAFEDetailID As String
oSelectedCell = dgAFEDetailGrid.CurrentCel
oSelectedItem = dgAFEDetailGrid.Item(oSele
intAFEDetailID = CStr(oSelectedItem)
'All is well, get dteModifed
If bFail = False Then
Dim frmAFEDetail As frmAFEDetail = New frmAFEDetail
'Associate the dataview to get Date Modified
dvMaintenance.Table = oDs.Tables("tblAFEDetail")
Dim drv As DataRowView 'Data Row View object to query DataView object
dvMaintenance.RowFilter = "[pkAFEDetailID] = " & intAFEDetailID
For Each drv In dvMaintenance
_dteDateModified2 = drv("dteDateModified")
frmAFEDetail.txtHiddenID.T
Next
If btnEditItem.Text = "View Item" Then
frmAFEDetail.lblEdit.Text = "Read Only"
frmAFEDetail.btnSaveItem.E
frmAFEDetail.btnNewItem.En
Else
frmAFEDetail.lblEdit.Text = "Edit Mode"
End If
'**********************SET
'Open User form and initialize
frmAFEDetail.txtHiddenID2.
frmAFEDetail.btnClearTop.V
frmAFEDetail.btnClearMiddl
frmAFEDetail.btnClearBotto
frmAFEDetail.ShowDialog()
'Refresh Main screen data
oDsGrid.Reset()
LoadDataGrid()
_bolRefreshMain = True 'Reset the refresh flag
Me.Activate()
Me.Cursor = System.Windows.Forms.Curso
End If
End If
End Sub