双击事件以将文本框填充到表单中 [英] Double click event to fill textbox in form
问题描述
我正在尝试使用工作表的双击事件,用来自双击行中特定列的值填充表单中的文本框.
I am trying to use double-click event of worksheet to populate a textbox in a form with value from a specific column in the double-clicked row.
例如
我有四列
ID Name Age Gender
1 A 24 M
2 B 26 F
3 C 22 F
4 D 30 M
当我双击列 Name
中的任何单元格时,将弹出一个带有文本框的表单,其中文本框填充了来自 Gender
列中的值双击的行.因此,当我双击名称"列中的"B"时,将弹出一个文本框值为"F"的表格.
When I double-click on any cell in the column Name
, a form with a textbox will pop up with the textbox filled with the value from the column Gender
in the row which was double-clicked. SO when I double-click on "B" in column Name a form should pop up with textbox value "F".
到目前为止,这是我的代码
this is my code so far
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, CANCEL As Boolean)
CANCEL = True
If Target.Column = 2 Then
Update.Show
With Update.TextBox1.value = ?????
End With
End If
End Sub
推荐答案
使用名为 frm_Update
的表单以及三个适当命名的文本框控件.
这将从 Target
行的第2、3和4列中获取值,并将这些值放置在文本框中:
Using a form called frm_Update
with three appropriately named text box controls.
This will take the value from the Target
row, columns 2, 3 and 4 and place the values in the textboxes:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim oForm As frm_Update
If Target.Column = 2 Then
Set oForm = New frm_Update
Cancel = True
With oForm
.txtName = Cells(Target.Row, 2)
.txtAge = Cells(Target.Row, 3)
.txtGender = Cells(Target.Row, 4)
.Show
End With
End If
End Sub
@Comintern-我将很好地阅读该链接.我真的应该把所有东西付诸实践.
@Comintern - I'm going to have a good read of that link. All stuff I really should put into practice.
这篇关于双击事件以将文本框填充到表单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!