Results 1 to 6 of 6

Thread: ShowDialog with data from parent form

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2021
    Posts
    20

    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 ...

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    37,412

    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

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,509

    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.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2021
    Posts
    20

    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.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,509

    Re: ShowDialog with data from parent form

    Quote Originally Posted by ivansmo View Post
    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.

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,822

    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…

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width