2014-11-13 4 views
0

DataGridView 복사본을 가져 오려고합니다.DataGridView 복사

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

그때 그때 할 DataGridView1의 구성을 변경 :

DataGridView1.Refresh() 
    DataGridView1.Visible = True 

나는 데 문제가 DataGridView1로 이루어집니다 만 원래 그리드가 변경되고 상쾌. 이것은 원래 표가 ByVal을 전달한다는 사실에도 불구하고 있습니다.

나는 전달 된 그리드, 열, 열, 행에 의해 행,하지만하여 나는 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 

초기화됩니다

"Provided column already belongs to the DataGridView control" 

오류를 얻을 처리 시도했습니다 추가 될 수 있습니다. 이 오류의 모든 인스턴스를 검색했지만 유일한 솔루션은 "데이터 소스 복사"라고 말합니다. 데이터 소스가 없습니다. 이것은 생성 된 테이블입니다. DataGridView 데이터를 DataSource로 변환하는 방법을 찾을 수 없습니다.

무엇이 누락 되었습니까? 어떤 제안?

+0

전달 된 그리드의 데이터를 원하십니까? – Codexer

+1

DGV 열은 구성 요소입니다. 'c = col' 라인은'c'가 더 이상 새로운 컬럼이 아니라 이미 * 소스에있는 컬럼을 참조 함을 의미합니다. 그러므로'col'를 사용하여 이미 소스 DGV에 속해 있기 때문에 dest DGV에'c '를 추가 할 수 없습니다. – Plutonix

답변

0

나는이 일을 결국했습니다

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

지금은 잘 작동하는 것 같다.