Private lastrow As Integer = 0
Private Sub InitDGW()
DataGridView1.BorderStyle = BorderStyle.Fixed3D
DataGridView1.Font = New Font("arial", 12, FontStyle.Bold)
DataGridView1.EnableHeadersVisualStyles = False
DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.PowderBlue
DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
DataGridView1.Columns.Add("TYPE", "THE TYPE")
DataGridView1.Columns.Add("COLOR", "THE COLOR")
End Sub
Private Sub FillDGW()
Dim n As Integer
n = DataGridView1.Rows.Add()
DataGridView1.Rows.Item(n).Cells("TYPE").Value = "AAA"
n = DataGridView1.Rows.Add()
DataGridView1.Rows.Item(n).Cells("TYPE").Value = "BBB"
n = DataGridView1.Rows.Add()
DataGridView1.Rows.Item(n).Cells("TYPE").Value = "CCC"
n = DataGridView1.Rows.Add()
DataGridView1.Rows.Item(n).Cells("TYPE").Value = "DDD"
n = DataGridView1.Rows.Add()
DataGridView1.Rows.Item(n).Cells("TYPE").Value = "EEE"
n = DataGridView1.Rows.Add()
DataGridView1.Rows.Item(n).Cells("TYPE").Value = "FFF"
n = DataGridView1.Rows.Add()
DataGridView1.Rows.Item(n).Cells("TYPE").Value = "GGG"
n = DataGridView1.Rows.Add()
DataGridView1.Rows.Item(n).Cells("TYPE").Value = "HHH"
DataGridView1.AutoSize = True
DataGridView1.AutoResizeColumns()
End Sub
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If e.RowIndex = 0 Then
Exit Sub
End If
For iter As Integer = lastrow + 1 To e.RowIndex - 1
DataGridView1.Rows(iter).Cells(e.ColumnIndex).Value = DataGridView1.Rows(lastrow).Cells(e.ColumnIndex).Value
Next
lastrow = e.RowIndex
End Sub
Private Sub paste()
Dim s As String = Clipboard.GetText()
Dim inter As Char() = s.ToCharArray()
s = ""
Dim i As Integer = 0
While i <> inter.Length
If inter(i) = ControlChars.Cr Then
Else
s = s + inter(i)
End If
i += 1
End While
Dim lines As String() = s.Split(ControlChars.Lf)
Dim row As Integer = DataGridView1.CurrentCell.RowIndex
Dim col As Integer = DataGridView1.CurrentCell.ColumnIndex
Dim a As Integer = 0
While a <> lines.Length
If row < DataGridView1.RowCount AndAlso lines(a).Length > 0 Then
Dim cells As String() = lines(a).Split(ControlChars.Tab)
For j As Integer = 0 To cells.GetLength(0) - 1
If col + j < Me.DataGridView1.ColumnCount Then
Dim roww As DataGridViewCell
For Each roww In DataGridView1.SelectedCells
DataGridView1(col + j, roww.RowIndex).Value = Convert.ChangeType(cells(j), DataGridView1(col + j, row).ValueType)
Next
Else
Exit For
End If
Next
row += 1
Else
Exit While
End If
a += 1
End While
End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDim mnu As New ContextMenuStrip()
Dim mnuCopy As New ToolStripMenuItem("Copier")
Dim mnuPaste As New ToolStripMenuItem("Coller")
AddHandler mnuCopy.Click, New EventHandler(AddressOf mnuCopy_Click)
AddHandler mnuPaste.Click, New EventHandler(AddressOf mnuPaste_Click)
mnu.Items.AddRange(New ToolStripItem() {mnuCopy, mnuPaste})
DataGridView1.ContextMenuStrip = mnu