【发布时间】:2016-09-21 09:24:49
【问题描述】:
我有 2 个相同形式的 Datagridview 控件。每个 Datagrid 都有一些列,用户将在其中编写长文本,因此我设计了带有 RichTextBox 的表单,当用户双击这些列以放大文本条目时会打开该表单。代码有效,但我想对两个 Datagrids 使用相同的表单,所以我应该以某种方式将文本返回到活动的 datagridview 单元格。这是我的代码(用于 Datagridview1):
TextZoomForm:
Public Class TextZoomForm
Public OpenedForm1 As New Form1
Private Sub RichTextBox1_DoubleClick(sender As Object, e As EventArgs) Handles RichTextBox1.DoubleClick
OpenedForm1.DataGridView1.CurrentCell.Value = RichTextBox1.Text
OpenedForm1.Label24.Focus()
Me.Close()
End Sub
Private Sub TextZoom_Load(sender As Object, e As EventArgs) Handles Me.Load
RichTextBox1.Text = OpenedForm1.DataGridView1.CurrentCell.Value
End Sub
End Class
Form1 中的DataGridView1_CellMouseDoubleClick:
Private Sub DataGridView1_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
If e.ColumnIndex = 1 Then
Dim cp = Cursor.Position
cp.Y += CInt(Cursor.Size.Height * (-0.5))
cp.X += CInt(Cursor.Size.Width * 0.8)
Dim f As New TextZoomForm()
f.OpenedForm1 = Me
f.Show()
f.Location = New Point(cp)
End If
End Sub
关于如何将文本返回到活动 datagridview 单元格的任何想法?
【问题讨论】:
标签: vb.net datagridview