Module Module1 Public ligne As Integer End Module
Private Sub DataGridView1_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick Dim y As Integer = DataGridView1.CurrentCellAddress.Y ligne = y Form2.Show() Form2.DataGridView1.Rows(ligne).Selected = True End Sub
Public Class Form2 Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim targetGrid As DataGridView = Me.DataGridView1 'Copy all rows and cells. Dim targetRows = New List(Of DataGridViewRow) For Each sourceRow As DataGridViewRow In Form1.DataGridView1.Rows If (Not sourceRow.IsNewRow) Then Dim targetRow = CType(sourceRow.Clone(), DataGridViewRow) 'The Clone method do not copy the cell values so we must do this manually. 'See: https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewrow.clone(v=vs.110).aspx For Each cell As DataGridViewCell In sourceRow.Cells targetRow.Cells(cell.ColumnIndex).Value = cell.Value Next targetRows.Add(targetRow) End If Next 'Clear target columns and then clone all source columns. targetGrid.Columns.Clear() For Each column As DataGridViewColumn In Form1.DataGridView1.Columns targetGrid.Columns.Add(CType(column.Clone(), DataGridViewColumn)) Next 'It's recommended to use the AddRange method (if available) 'when adding multiple items to a collection. targetGrid.Rows.AddRange(targetRows.ToArray()) Me.DataGridView1.MultiSelect = False End Sub End Class
16 juil. 2016 à 09:09
Modifié par psofie le 16/07/2016 à 17:58
je vous remercie pour vos réponses j'ai fait un sub change
sub change
ligne = y
Form2.Show()
Form2.DataGridView1.Rows(ligne).Selected = True
end sub
et je l'appel appartir des boutons de déplacement et ça marche qui figure dans le form2 mais réagissent sur le grid du form1
je ne peut pas le faire au moment des Evénements DataGridView1_CellContentClick ou DataGridView1_selectionchanged
car çà marche pas
maintenant mon seule problème et comment afficher les mêmes contenus dans les deux datagrid au moment du load du form2 ?l es deux grid affichent le même dataset mais si je fait une recherche et je l'affiche dans le grid du form1 comment faire pour afficher le même contenue dans le grid du form2 ?? Merci d'avance
16 juil. 2016 à 18:05
voici le code si vous pouvez me corriger
Private Sub PictureBox3_Click(sender As Object, e As EventArgs) Handles PictureBox3.Click
Try
Dim prevRowNum As Integer = (photos1.MetroGrid1.Rows.Count 0)
Dim curDataGridViewRow As DataGridViewRow = photos1.MetroGrid1.CurrentRow
Dim curRowNum As Integer = curDataGridViewRow.Index
If (curRowNum >= prevRowNum) Then
MsgBox("No more rows")
Else
Dim nextRow As DataGridViewRow = photos1.MetroGrid1.Rows(curRowNum - 1)
photos1.MetroGrid1.CurrentCell = nextRow.Cells(0)
nextRow.Selected = True
charng()
End If
Me.StartPosition = FormStartPosition.CenterParent
PictureBox1.Location = New Point((Screen.PrimaryScreen.WorkingArea.Width - PictureBox1.Width) / 2, (Screen.PrimaryScreen.WorkingArea.Height - PictureBox1.Height) / 2)
Me.WindowState = FormWindowState.Maximized
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
je crois que le problème figure dans cette ligne
pour définir la 1er ligne du grid et puis vérifier s il nya plus de ligne en haut
Dim prevRowNum As Integer = (photos1.MetroGrid1.Rows.Count 0)