簡體   English   中英

復制一個DataGridView

[英]Copy a DataGridView

我正在嘗試獲取DataGridView的副本。

Public Sub CopyDataView(ByVal inGrid As DataGridView,
                        ByVal inPrintHiddenCols As Boolean)
    DataGridView1 = inGrid

然后,我更改DataGridView1的配置,然后執行以下操作:

    DataGridView1.Refresh()
    DataGridView1.Visible = True

我遇到的問題已經解決了DataGridView1,只有原始網格被更改和刷新了。 盡管原始網格通過了ByVal,但事實並非如此。

我嘗試處理傳遞的網格,列,列,行,行,但出現錯誤

"Provided column already belongs to the DataGridView control"

DataGridView1已初始化

    Cursor.Current = Cursors.WaitCursor
    Try
        DataGridView1.Columns.Clear()
        DataGridView1.Rows.Clear()
        DataGridView1.AutoSize = True
        DataGridView1.AutoGenerateColumns = False
        DataGridView1.RowHeadersVisible = False

            For Each col As DataGridViewColumn In inGrid.Columns
            If col.Width = 0 Or _
               col.Displayed = False And _
               Not (inPrintHiddenCols) Then
                SkipCells.Add(col.Index)
            Else
                Dim c As New DataGridViewColumn
                c = col
                DataGridView1.Columns.Add(c)  ' <----------------------
                ColWidth_CSV.Add(modFunctions.GetWidthOfText(col.Width, f))
            End If
        Next

在要添加的第一列上。 我搜索了此錯誤的所有實例,但是唯一的解決方案是“復制數據源”,沒有數據源,這是一個生成的表。 我也找不到將DataGridView數據轉換為DataSource的方法。

我想念什么? 有什么建議么?

我最終這樣做了:

Dim c As New DataGridViewColumn
c = col.Clone
DataGridView1.Columns.Add(c)

我現在似乎工作正常。

暫無
暫無

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

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