-
May 18th, 2022, 03:50 PM
#1
Thread Starter
Junior Member
ShowDialog with data from parent form
So, this is what I want
Code:
Private Sub DataGridView2_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView2.CellMouseClick
If e.RowIndex >= 0 Then
Dim f As New Form
f.ShowDialog(Me)
Dim textIneed As String
textIneed = Me.DataGridView2.CurrentRow.ToString
End If
End Sub
Basically, on user click, DatagridView2 app calls FormDialog where I want to show ToString values from that row, and it's every column. I have three columns and I prefer to show data like Label.text if possible.
Thank you all ...
-
May 18th, 2022, 04:43 PM
#2
Re: ShowDialog with data from parent form
Well, that just means that you need to get the data to the new form. You have several different ways you can do that. You can add properties to the form and fill them in between creating the form and showing the form, or you can create a custom constructor for the form and pass the arguments to that, and a third way would be to have the new form go get the data from the parent, though that's the worst of the three in most cases.
You can pass in as many fields as you want, or you can pass in the entire DataRowView so that you have the whole row.
My usual boring signature: Nothing
 
-
May 18th, 2022, 08:37 PM
#3
Re: ShowDialog with data from parent form
It's worth noting that what Shaggy has described is exactly how you get data into any other object. For example, if you want to get text into a TextBox, what do you do? You set its Text property, right? Why should getting data into a form be any different? Forms are objects like any other, so you treat them like you would any other objects. That means that you set a property or call a method and pass an argument to get data in. Constructors are special methods but they are still methods.
-
May 19th, 2022, 05:22 PM
#4
Thread Starter
Junior Member
Re: ShowDialog with data from parent form
I misunderstood something.
Actually, I need to create a Form and make a design for that form? For some reason, I thought I can call a standardized Form (ShowDialog) this way and pass the details I want programmatically? Without actually designing a Form... and adding properties (elements) inside.
-
May 19th, 2022, 08:12 PM
#5
Re: ShowDialog with data from parent form
 Originally Posted by ivansmo
I thought I can call a standardized Form (ShowDialog) this way and pass the details I want programmatically? Without actually designing a Form... and adding properties (elements) inside.
You could do that but the form would be blank by default. You would need code somewhere, either in the form or elsewhere, to add whatever controls you need and to process the data in those controls. That's not something you would usually do.
-
May 20th, 2022, 03:34 AM
#6
Re: ShowDialog with data from parent form
Why not a Form you’ve designed at design time? You can add controls to a Form at run time, but in most cases you wouldn’t…
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
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
|