簡體   English   中英

使用WPF dataGrid復制和粘貼

[英]Copy and paste with a WPF dataGrid

我正在使用WPF和Visual Basic。 我試圖有一個按鈕,該按鈕允許從我擁有的DataGrid中進行復制。 我似乎沒有做任何事情允許我訪問所選的數據,並使用僅觸發不知道如何在DataGrid上觸發復制事件的替代方法。 這是一個失敗的代碼示例:

Private Sub btnFECopy_Click(sender As Object, e As RoutedEventArgs) Handles btnFECopy.Click
    Dim text As New System.Text.StringBuilder()

    For Each row As DataGridCellInfo In dgFileEditorWindow.SelectedCells
        For Each cell As System.Data.DataRowView In row.Item
            If Not text.Equals("") Then
                text.Append(";")
            End If
            text = text.Append(cell.ToString)
            'MsgBox(cell.Column.DisplayIndex)
            'MsgBox(dataGrid1.Items.IndexOf(cell.Item))
        Next
    Next

    'Nothing text.Append(dgFileEditorWindow.CurrentCell.Item.ToString())

    'Nothing Console.WriteLine(dgFileEditorWindow.CurrentCell.ColumnNumber & " " & dgFileEditorWindow.CurrentCell.RowNumber)

        Clipboard.SetText(text.ToString())
End Sub

有什么提示嗎?

這是一個基本示例:

我創建了一個帶按鈕的datagridview。

該按鈕循環遍歷選定的datagridviewcell

 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim text As New System.Text.StringBuilder()

    For Each dgvr As DataGridViewCell In DataGridView1.SelectedCells
        If Not Text.Equals("") Then
            Text.Append(";")
        End If

    Next

    Clipboard.SetText(text.ToString())
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM