我有一个简单的空白窗体作为测试项目 和datagridview 和一个填充datagridview的查询
在这个测试项目中。我可以突出显示所有列和行
单击CTRL + C
打开excel
然后点击ctrl + V
并且数据在那里。
但在我从公司某人那里继承的程序中 我有一个类似的数据网格视图。但我无法复制粘贴
我如何识别这里有什么区别? 我检查了测试项目和我继承的程序的数据网格视图属性。两者都有相同的以下内容: 1.只读=假 2. copyclipboardmode = EnableWithAutoHeaderText
还有什么可以阻止我复制粘贴这个值?
在继承的程序中,通过双击单元格并复制粘贴ist的唯一方法,但是。这限制我一次复制一个单元格而不是多个单元格
请指教?
谢谢
这是我测试项目的代码片段
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
DataGridView1.Rows.Add(New String() {"TEST", "TEST2", "TEST3"})
DataGridView1.Rows.Add(New String() {"TEST", "TEST2", "TEST3"})
DataGridView1.Rows.Add(New String() {"TEST", "TEST2", "TEST3"})
DataGridView1.Rows.Add(New String() {"TEST", "TEST2", "TEST3"})
DataGridView1.Rows.Add(New String() {"TEST", "TEST2", "TEST3"})
DataGridView1.Rows.Add(New String() {"TEST", "TEST2", "TEST3"})
DataGridView1.Rows.Add(New String() {"TEST", "TEST2", "TEST3"})
End Sub
这是QuickDanger要求的frmForm.Designer.vb
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmForm
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.dgvSpecials = New System.Windows.Forms.DataGridView()
Me.btnCreate = New System.Windows.Forms.Button()
Me.PartCode = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.PDF = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.SLDDRW = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.SLDPRT = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.BasePartCode = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.TEMPLATESLDDRW = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.TEMPLATESLDPRT = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.TEMPLATEDRWFILE = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.TEMPLATEPRTFILE = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.MakeSpecial = New System.Windows.Forms.DataGridViewCheckBoxColumn()
CType(Me.dgvSpecials, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'dgvSpecials
'
Me.dgvSpecials.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
Me.dgvSpecials.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.PartCode, Me.PDF, Me.SLDDRW, Me.SLDPRT, Me.BasePartCode, Me.TEMPLATESLDDRW, Me.TEMPLATESLDPRT, Me.TEMPLATEDRWFILE, Me.TEMPLATEPRTFILE, Me.MakeSpecial})
Me.dgvSpecials.Dock = System.Windows.Forms.DockStyle.Fill
Me.dgvSpecials.Location = New System.Drawing.Point(0, 0)
Me.dgvSpecials.Name = "dgvSpecials"
Me.dgvSpecials.Size = New System.Drawing.Size(917, 246)
Me.dgvSpecials.TabIndex = 0
'
'btnCreate
'
Me.btnCreate.Dock = System.Windows.Forms.DockStyle.Bottom
Me.btnCreate.Location = New System.Drawing.Point(0, 246)
Me.btnCreate.Name = "btnCreate"
Me.btnCreate.Size = New System.Drawing.Size(917, 30)
Me.btnCreate.TabIndex = 1
Me.btnCreate.Text = "Create"
Me.btnCreate.UseVisualStyleBackColor = True
'
'PartCode
'
Me.PartCode.HeaderText = "Part Code"
Me.PartCode.Name = "PartCode"
Me.PartCode.ReadOnly = True
Me.PartCode.Width = 200
'
'PDF
'
Me.PDF.HeaderText = "PDF"
Me.PDF.Name = "PDF"
Me.PDF.ReadOnly = True
'
'SLDDRW
'
Me.SLDDRW.HeaderText = "SLDDRW"
Me.SLDDRW.Name = "SLDDRW"
Me.SLDDRW.ReadOnly = True
'
'SLDPRT
'
Me.SLDPRT.HeaderText = "SLDPRT"
Me.SLDPRT.Name = "SLDPRT"
Me.SLDPRT.ReadOnly = True
'
'BasePartCode
'
Me.BasePartCode.HeaderText = "Base Part"
Me.BasePartCode.Name = "BasePartCode"
Me.BasePartCode.ReadOnly = True
'
'TEMPLATESLDDRW
'
Me.TEMPLATESLDDRW.HeaderText = "DRW Template"
Me.TEMPLATESLDDRW.Name = "TEMPLATESLDDRW"
Me.TEMPLATESLDDRW.ReadOnly = True
'
'TEMPLATESLDPRT
'
Me.TEMPLATESLDPRT.HeaderText = "PRT Template"
Me.TEMPLATESLDPRT.Name = "TEMPLATESLDPRT"
'
'TEMPLATEDRWFILE
'
Me.TEMPLATEDRWFILE.HeaderText = "Column1"
Me.TEMPLATEDRWFILE.Name = "TEMPLATEDRWFILE"
Me.TEMPLATEDRWFILE.ReadOnly = True
Me.TEMPLATEDRWFILE.Visible = False
'
'TEMPLATEPRTFILE
'
Me.TEMPLATEPRTFILE.HeaderText = "Column1"
Me.TEMPLATEPRTFILE.Name = "TEMPLATEPRTFILE"
Me.TEMPLATEPRTFILE.ReadOnly = True
Me.TEMPLATEPRTFILE.Visible = False
'
'MakeSpecial
'
Me.MakeSpecial.HeaderText = "MakeSpecial"
Me.MakeSpecial.Name = "MakeSpecial"
'
'frmForm
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(917, 276)
Me.Controls.Add(Me.dgvSpecials)
Me.Controls.Add(Me.btnCreate)
Me.Name = "frmForm"
Me.Text = "frmForm"
CType(Me.dgvSpecials, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
Friend WithEvents dgvSpecials As System.Windows.Forms.DataGridView
Friend WithEvents btnCreate As System.Windows.Forms.Button
Friend WithEvents PartCode As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents PDF As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents SLDDRW As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents SLDPRT As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents BasePartCode As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents TEMPLATESLDDRW As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents TEMPLATESLDPRT As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents TEMPLATEDRWFILE As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents TEMPLATEPRTFILE As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents MakeSpecial As System.Windows.Forms.DataGridViewCheckBoxColumn
End Class
这是实际的frmForm.VB SldWorks是SolidWorks.Interop.sldworks
的成员Imports SolidWorks.Interop.sldworks
Public Class frmForm
Dim App As SldWorks
Public Sub Setup(App As SldWorks, Arr As ArrayList)
End Sub
Private Sub btnCreate_Click(sender As Object, e As EventArgs) Handles btnCreate.Click
End Sub
End Class
答案 0 :(得分:1)
我猜你必须将DataGridView的MultiSelect
属性设置为true
答案 1 :(得分:1)
我猜你已将ClipboardCopyMode
设为Disable
。将此属性更改为任何其他三个可用选项。
答案 2 :(得分:1)
看起来其他人在ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText
取得了成功
(见this SO question)。如果这没有帮助,你可以粘贴dataGridView的设计器代码吗? (可在项目文件[formname] .Designer.vb中找到)
您可能还希望在代码中搜索对此控件的引用,并验证原始开发人员是否在运行时未修改ClipboardCopyMode
属性。
编辑:由于所有建议似乎都无效,您可以使用制表符分隔格式“滚动自己的”复制/粘贴版本:
注意:这会复制所有数据,而不仅仅是选定的单元格,但您可以将其修改为仅执行选定的单元格。
Private Sub DataGridView1_KeyUp(sender As Object, e As KeyEventArgs) Handles DataGridView1.KeyUp
If e.KeyCode = Keys.C AndAlso e.Control Then
Dim sb = New StringBuilder()
' If you want the headers, keep these two lines
Dim headers = DataGridView1.Columns.Cast(Of DataGridViewColumn)()
sb.AppendLine(String.Join(vbTab, headers.[Select](Function(column) Convert.ToString(column.HeaderText)).ToArray()))
For Each row As DataGridViewRow In DataGridView1.Rows
Dim cells = row.Cells.Cast(Of DataGridViewCell)()
sb.AppendLine(String.Join(vbTab, cells.[Select](Function(cell) Convert.ToString(cell.Value)).ToArray()))
Next
My.Computer.Clipboard.SetText(sb.ToString)
End If
End Sub
答案 3 :(得分:1)
其他开发人员在他的项目中使用Ctrl + C作为某些快捷键。 如果您可以查看他的设计,请浏览菜单栏 - &gt; ShortcutKeys
的财产答案 4 :(得分:0)
解决:此问题是由solidWorks.Interop.sldworks和应用程序在Solidworks环境中引起的
我从其他solidworks开发者那里听说ctrl C拒绝工作
答案 5 :(得分:0)
要从datagridview复制数据,我们会遇到多个错误。因此,为此,我在上面的QuickDanger的帮助下为此应用开发了以下代码。
Private Sub grdDetails_KeyUp(sender As Object, e As KeyEventArgs) Handles grdDetails.KeyUp
Try
If e.KeyCode = Keys.C AndAlso e.Control Then
Dim mGrid As DataGridView, mCol As DataGridViewColumn, mRow As DataGridViewRow, mCell As DataGridViewCell
Dim mStrBld As New StringBuilder
mGrid = CType(sender, DataGridView)
' Copying Header
For Each mCol In mGrid.Columns
If mCol.HeaderText IsNot Nothing Then
mStrBld.Append(vbTab & mCol.HeaderText)
Else
mStrBld.Append(vbTab & "")
End If
Next
mStrBld.Append(vbCrLf)
' Copying Data
If mGrid.Rows.Count > 0 Then
'Display progress in Progress Bar if rows are more
'ProgressBar1.Minimum = 0 : ProgressBar1.Value = 0 : ProgressBar1.Maximum = mGrid.Rows.Count : ProgressBar1.Step = 1 : ProgressBar1.Visible = True
For Each mRow In mGrid.Rows
For Each mCell In mRow.Cells
If mCell IsNot Nothing AndAlso mCell.Value IsNot Nothing Then
mStrBld.Append(vbTab & mCell.Value.ToString)
Else
mStrBld.Append(vbTab & "")
End If
Next
mStrBld.Append(vbCrLf)
'ProgressBar1.PerformStep()
Next
' sending data to clipboard, so we can safely past the same
My.Computer.Clipboard.SetText(mStrBld.ToString)
'ProgressBar1.Visible = False
Else
MsgBox("No Data...1", MsgBoxStyle.Critical)
End If
End If
e.Handled = True
Catch ex As Exception
MsgBox("Error:" & ex.Message)
End Try
End Sub