Datagridview

mohamed222222 Messages postés 161 Date d'inscription mardi 12 juin 2007 Statut Membre Dernière intervention 22 avril 2009 - 14 nov. 2008 à 17:26
mohamed222222 Messages postés 161 Date d'inscription mardi 12 juin 2007 Statut Membre Dernière intervention 22 avril 2009 - 17 nov. 2008 à 10:52
Bonjour,

Dans mon interface je charge un datagridview que je nomme datgridview1. Ensuite je souhaiterai affecté les valeurs de ce datagridview1 à un autre datagridview que je nomme datagridview2. Pour cela je fais :

dim datagrdiview2 as datagridview
datagrdiview2=datagrdiview1

Cela marche bien par contre quand je modifie une propriété du datagridview2 il modifie automatiquement celui du datagridview1.
Comment faire fasse à ce problème ?

merci d'avance

Bon WE

4 réponses

nhervagault Messages postés 6063 Date d'inscription dimanche 13 avril 2003 Statut Membre Dernière intervention 15 juillet 2011 37
14 nov. 2008 à 19:06
Salut

C'est la même référence,
il faut normalement dupliqué ou cloner l'objet pour avoir deux réferences différentes.
0
mohamed222222 Messages postés 161 Date d'inscription mardi 12 juin 2007 Statut Membre Dernière intervention 22 avril 2009
15 nov. 2008 à 15:25
salut,


Comment pourrai-je faire ?


Merci d'avance.
0
nhervagault Messages postés 6063 Date d'inscription dimanche 13 avril 2003 Statut Membre Dernière intervention 15 juillet 2011 37
15 nov. 2008 à 16:36
Pourquoi veux-tu copier une datagridview dans une autre?

Le clone ne marche pas.
Il faut recreer de toute piece des colonnes et apres les lignes.

Quel est l'interet de l'operation??

regardes le post suivanttu auras peut etre la réponse.
0
mohamed222222 Messages postés 161 Date d'inscription mardi 12 juin 2007 Statut Membre Dernière intervention 22 avril 2009
17 nov. 2008 à 10:52
Bonjour,

j'utilise ce code pour imprimer le contenu de mon  datagridview :

 Private Sub ControlPrint_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles MyBase.PrintPage
            Dim position As Integer = 0


            Dim NewSize As New Size(width, height)
            Dim OldDock As DockStyle = m_ctrl.Dock
            Dim OldSize As New Size(m_ctrl.Width, m_ctrl.Height)


            Dim i As Integer = 0
           Dim colonneVisible As Boolean = False


            Page = Page + 1


            position = position + 40


            If Page = 1 Then
                e.Graphics.DrawString(critere.ToString, New Font("Arial", 10, FontStyle.Italic), Brushes.Black, 10, position)
           End If


            m_ctrl.Dock = DockStyle.None
            m_ctrl.Size = NewSize
            m_ctrl.BorderStyle = BorderStyle.None


            If m_ctrl.Columns("Solder").Visible = True Then
                colonneVisible = True
                m_ctrl.Columns("Solder").Visible = False
                m_ctrl.Columns("Reessayer").Visible = False
            End If


            Dim printwidth As Integer = width
            Dim printheight As Integer = height


            If printwidth > e.MarginBounds.Width Then
                printheight = CInt(Fix((CSng(e.MarginBounds.Width) / CSng(printwidth)) * printheight))
                printwidth = e.MarginBounds.Width
            End If


            If printheight - printedheight > e.MarginBounds.Height Then
                e.HasMorePages = True
            Else
                e.HasMorePages = False
            End If


            Dim longueur As Integer = 0


            Dim gp As GraphicsUnit = GraphicsUnit.Display
            Dim b As New Bitmap(width, height)


            m_ctrl.DrawToBitmap(b, New Rectangle(0, 0, width, height))


            Dim ScaleF As Single = CSng(height) / CSng(printheight)
            printheight -= printedheight
            If printheight > e.MarginBounds.Height Then
                printheight = e.MarginBounds.Height
            End If


            Dim rect As New Rectangle(0, CInt(Fix(printedheight * ScaleF)), b.Width, CInt(Fix(printheight * ScaleF)))
            Dim b2 As Bitmap = b.Clone(rect, System.Drawing.Imaging.PixelFormat.DontCare)
            e.Graphics.DrawImage(b2, 40, position + 40, printwidth, printheight)


            If e.HasMorePages Then
                printedheight += e.MarginBounds.Height - inbetween
            Else
                printedheight = 0
            End If


            e.Graphics.DrawString(Now.ToString, New Font("Arial", 6, FontStyle.Italic), Brushes.Black, 1000, 750)
            e.Graphics.DrawString(Page.ToString, New Font("Arial", 6, FontStyle.Italic), Brushes.Black, 600, 750)


            If colonneVisible = True Then
                m_ctrl.Columns("Solder").Visible = True
                m_ctrl.Columns("Reessayer").Visible = True
            End If


            m_ctrl.Size = New Size(OldSize.Width, OldSize.Height)
            m_ctrl.Dock = OldDock


        End Sub

Par contre je change la propriété de mon datagridview car je ne souhaite  pas imprimer toutes les colonnes de mon datagridview.

Aider moi SVP, je suis entrain de galérer !!

Merci d'avance.
0
Rejoignez-nous