Hello everyone,

I have a problem as every newbie :)

I'm using vvb express 2013 and opening my windows with below code (credit goes to the owner, thanks to him btw) to prevent the form from opening twice:

If Me.yenifaturaekle Is Nothing OrElse _
      Me.yenifaturaekle.IsDisposed Then
        Me.yenifaturaekle = New Yeni_Alış_Faturası
        yenifaturaekle.MdiParent = Giriş
        yenifaturaekle.Dock = DockStyle.Fill
        yenifaturaekle.Show()            
    Else
        'A Tool window is currently open.
        Me.yenifaturaekle.Activate()
    End If

The problem is :

I know the code to pass a dgv cell data to a textbox or label which is on another form :

    form2.Label2.Text = Me.dgv.CurrentRow.Cells(0).Value
    form2.IdTextBox.Text = Me.dgv.CurrentRow.Cells(0).Value

but that code doesn't work with this code.
it works with standart form2.show() command but not with above one.
Maybe i placed it somewhere wrong.

Any ideas?

Thanks for your help in advance.

There is no cause to interrupt the execution of your codes. You should initialized the Object variable yenifaturaekle when application starts and also when the ChildForm closes. You can do some thing like this.

    Imports System.Windows.Forms

    Public Class MDIParent1

        Dim yenifaturaekle As New Form1

        Private Sub MDIParent1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            'Initialize object variable 
            yenifaturaekle = Nothing
        End Sub

        Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click

            'Show the object.

            If yenifaturaekle Is Nothing OrElse _
          Me.yenifaturaekle.IsDisposed Then
                yenifaturaekle = New Form1
                yenifaturaekle.MdiParent = Me
                yenifaturaekle.Dock = DockStyle.Fill
                yenifaturaekle.Show()

            Else
                yenifaturaekle.Activate()
            End If

'********************************************
'Do here your codes to display data
'********************************************

        End Sub

        Private Sub CloseAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CloseAllToolStripMenuItem.Click
            ' Dispose and Initialize 
            yenifaturaekle.Close()
            yenifaturaekle.Dispose()

            yenifaturaekle = Nothing

        End Sub


    End Class

Thanks for your early reply but opening and closing forms code works.
The code for passind the dgv variable to new form code doesn't work and it is not on the parent form.

Here is the complete code for openformbutton.click event:

Private Sub Alış_FaturasıDataGridView_RowHeaderMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles Alış_FaturasıDataGridView.RowHeaderMouseDoubleClick
    If Me.yenifaturaekle Is Nothing OrElse _
  Me.yenifaturaekle.IsDisposed Then
        'The tool window has not been opened or it has been opened and closed.
        Me.yenifaturaekle = New Yeni_Alış_Faturası
        yenifaturaekle.MdiParent = Giriş
        yenifaturaekle.Dock = DockStyle.Fill
        yenifaturaekle.Show()            
    Else
        'A Tool window is currently open.
        Me.yenifaturaekle.Activate()
    End If
    ' the code below doesn't works.
    Yeni_Alış_Faturası.Label2.Text = Me.Alış_FaturasıDataGridView.CurrentRow.Cells(0).Value
    Yeni_Alış_Faturası.IdTextBox.Text = Me.Alış_FaturasıDataGridView.CurrentRow.Cells(0).Value

End Sub

and i also declare the form at :

Public Class Alış_Faturaları
    Private yenifaturaekle
    .
    .
    .

section.

I think i need a new to pass the dgv cell data to a textbox which i on yenifaturaekle.

Ohoooo! you do the same wrong. Why are you call the form in its designed name Yeni_Alış_Faturası. Instead it, call the object variable yenifaturaekle, in which holds the reference of the form Yeni_Alış_Faturası. Replace your code with at the lines 14 & 15.

yenifaturaekle.Label2.Text = Me.Alış_FaturasıDataGridView.CurrentRow.Cells(0).Value
    yenifaturaekle.IdTextBox.Text = Me.Alış_FaturasıDataGridView.CurrentRow.Cells(0).Value

then it says idtextbox.text is not a member of yenifaturaekle.

anyway i workaround the proble with a global variable.

Thank you very much for your help again.

Remove "Me" keyword from line No 5

Replace line 5 with

yenifaturaekle = New Yeni_Alış_Faturası
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.