Results 1 to 13 of 13

Thread: DataGridViews

  1. #1

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    Angry DataGridViews

    Hello to you all...

    I have 2 forms, each one with a datagridview.
    I want to transfer all the DataGridView Rows from From2 to another DataGridView of Form1... but it's not possible... why ?

    Code:
        Public Sub publicare_parteneri()
    
            For Each row As DataGridViewRow In Me.dgv_lista_parteneri_proiect.Rows
    
                Dim n As Integer = frm_gestionare_proiecte.dgv_parteneri.Rows.Add()
    
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(0).Value = row.Cells(0).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(1).Value = row.Cells(1).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(2).Value = row.Cells(2).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(3).Value = row.Cells(3).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(4).Value = row.Cells(4).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(5).Value = row.Cells(5).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(6).Value = row.Cells(6).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(7).Value = row.Cells(7).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(8).Value = row.Cells(8).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(9).Value = row.Cells(9).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(10).Value = row.Cells(10).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(11).Value = row.Cells(11).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(12).Value = row.Cells(12).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(13).Value = row.Cells(13).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(14).Value = row.Cells(14).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(15).Value = row.Cells(15).Value
                frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(16).Value = frm_gestionare_proiecte.txt_id_proiect.Text
    
                frm_gestionare_proiecte.Validate()
                frm_gestionare_proiecte.dgv_parteneri.EndEdit()
                frm_gestionare_proiecte.dgv_parteneri.Update()
    
                'MessageBox.Show(frm_gestionare_proiecte.dgv_parteneri.Rows(n).Cells(4).Value.ToString & vbCrLf & vbCrLf & n.ToString, "Valoare", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    
            Next
    
        End Sub
    None of DGV's is bounded... all it's programmatically data...

    What's wrong ?
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: DataGridViews

    try this:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     For Each row As DataGridViewRow In Me.dgv_lista_parteneri_proiect.Rows
    3.         If row.IsNewRow Then Exit For
    4.         Dim cells As New List(Of Object)(Array.ConvertAll(row.Cells.Cast(Of DataGridViewCell).ToArray, Function(c As DataGridViewCell) If(c.Value IsNot Nothing, c.Value.ToString, "")))
    5.         cells.Add(frm_gestionare_proiecte.txt_id_proiect.Text)
    6.         frm_gestionare_proiecte.dgv_parteneri.Rows.Add(cells.ToArray)
    7.     Next
    8. End Sub

  3. #3

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    Re: DataGridViews

    Nope... it's not working...
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: DataGridViews

    in what way is it not working? it worked ok for me when i tested it so there must be circumstances you haven't mentioned. is frm_gestionare_proiecte open when you run the code?

  5. #5
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: DataGridViews

    In regards to .Paul. solution does the target DataGridView have columns setup prior to attempting to copy rows from the one DataGridView to the other DataGridView?

    If not then run the following before running .Paul. code

    Code:
    frm_gestionare_proiecte.dgv_parteneri.CloneColumns(Me.dgv_lista_parteneri_proiect)
    Place this code in a code module
    Code:
    <Runtime.CompilerServices.Extension()> _
    Public Sub CloneColumns(ByVal Self As DataGridView, ByVal CloneFrom As DataGridView)
        If Self.ColumnCount = 0 Then
            For Each c As DataGridViewColumn In CloneFrom.Columns
                Self.Columns.Add(CType(c.Clone, DataGridViewColumn))
            Next
        End If
    End Sub

  6. #6

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    Re: DataGridViews

    Sorry for my delay...

    Form 1 it's an MDI Child and i think that's the problem...

    I've made into Form1 (MDI Child) a "Public Sub" and i think it's more simple like this...

    But now the problem is that i can not call this Public Sub (of form1 - mdi child) from the Form2 when i close this form.

    Code:
     
    
       Private Sub btn_iesire_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_iesire.Click
    
                  frm_gestionare_proiecte.afisare_parteneri()
    Me.Close()
    
        End Sub
    Last edited by Alexandru_mbm; Mar 14th, 2011 at 04:51 PM.
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: DataGridViews

    the problem is probably because your mdi child forms are instances

    i.e.

    vb Code:
    1. dim frm1 as new form1
    2. dim frm2 as new form2

    you need to refer to the forms by the instance names

  8. #8

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    Re: DataGridViews

    MDI Child contains a DataGridView and is opening with this Code from the Parent

    Code:
        Private Sub ProiecteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProiecteToolStripMenuItem.Click
    
            Dim frm_gestionare_proiecte_frm As New frm_gestionare_proiecte
            frm_gestionare_proiecte_frm.MdiParent = Me
            frm_gestionare_proiecte_frm.Show()
            frm_gestionare_proiecte_frm.WindowState = FormWindowState.Maximized
    
         End Sub
    The MDI Child DGV is populating using a "Public Sub afisare_parteneri()".

    On this MDI Child (frm_gestionare_proiecte_frm) i have a Link Label that opens a Form (not another MDI Child or Parent) named frm_gestionare_parteneri with this code

    Code:
        Private Sub lkl_gestionare_parteneri_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lkl_gestionare_parteneri.LinkClicked
    
            If Me.txt_numarul_cererii_de_depunere_de_proiecte.Text <> String.Empty AndAlso Me.txt_numar_dmi.Text <> String.Empty AndAlso Me.txt_tip_proiect.Text <> String.Empty AndAlso Me.txt_id_proiect.Text <> String.Empty Then
    
                frm_gestionare_parteneri.lbl_numar_proiect.Text = Me.txt_numarul_cererii_de_depunere_de_proiecte.Text & "/" & Me.txt_numar_dmi.Text & "/" & Me.txt_tip_proiect.Text & "/" & Me.txt_id_proiect.Text
                frm_gestionare_parteneri.id_proiect = Me.txt_id_proiect.Text
                frm_gestionare_parteneri.Show()
    
            Else
    
                MessageBox.Show("Va rugam sa completati numarul contractului in totalitate inainte de definirea activitatilor.", "Avertizare", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Me.txt_numarul_cererii_de_depunere_de_proiecte.Select()
    
            End If
    
        End Sub

    The form frm_gestionare_parteneri contanins a DataGridView where i add some values...

    The problem is how can i transfer the Values added in the Form frm_gestionare_parteneri DGV to the MDI Child frm_gestionare_proiecte_frm DGV

    Because when i call frm_gestionare_proiecte_frm.afisare_parteneri() nothing happends...
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: DataGridViews

    how large is your project? could you upload it?

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: DataGridViews

    here's an experiment i did, using an mdi form, a child form + an independent form:

    vb Code:
    1. Public Class Form1
    2.     'this is the mdi form. form2 is the mdichild + form3 is the independent form
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Dim frm As New Form2
    5.         frm.MdiParent = Me
    6.         frm.Show()
    7.     End Sub
    8.  
    9. End Class

    vb Code:
    1. Public Class Form2
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         Form3.Show()
    5.         Me.AddOwnedForm(Form3)
    6.     End Sub
    7.  
    8. End Class

    vb Code:
    1. Public Class Form3
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         MsgBox(Me.Owner.Name)
    5.     End Sub
    6.  
    7. End Class

  11. #11

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    Re: DataGridViews

    Please check your PM
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: DataGridViews

    ok. try this. it's difficult for me to give you a better answer. language barrier

    vb Code:
    1. Private Sub lkl_gestionare_parteneri_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lkl_gestionare_parteneri.LinkClicked
    2.  
    3.     If Me.txt_numarul_cererii_de_depunere_de_proiecte.Text <> String.Empty AndAlso Me.txt_numar_dmi.Text <> String.Empty AndAlso Me.txt_tip_proiect.Text <> String.Empty AndAlso Me.txt_id_proiect.Text <> String.Empty Then
    4.  
    5.         frm_gestionare_parteneri.lbl_numar_proiect.Text = Me.txt_numarul_cererii_de_depunere_de_proiecte.Text & "/" & Me.txt_numar_dmi.Text & "/" & Me.txt_tip_proiect.Text & "/" & Me.txt_id_proiect.Text
    6.         frm_gestionare_parteneri.id_proiect = Me.txt_id_proiect.Text
    7.         frm_gestionare_parteneri.Show()
    8.         Me.AddOwnedForm(frm_gestionare_parteneri)
    9.  
    10.     Else
    11.  
    12.         MessageBox.Show("Va rugam sa completati numarul contractului in totalitate inainte de definirea activitatilor.", "Avertizare", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    13.         Me.txt_numarul_cererii_de_depunere_de_proiecte.Select()
    14.  
    15.     End If
    16.  
    17. End Sub

    then to refer to the child frm_gestionare_proiecte form from frm_gestionare_parteneri:

    vb Code:
    1. DirectCast(Me.Owner, frm_gestionare_proiecte)

  13. #13
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: DataGridViews

    is that helping?

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