VB.net 控件数据的事件如何处理。
我是刚从6.0迁移到net的。所以算是新手,请大家多多帮助。我的问题是我需要做一个数据库管理窗口,如图。我已经实现了根据datagridview的数据结构动态建立控件(Label和Textbox)。属性修改我已经可以实现
但是现在有两个问题,
1. 如何实现动态建立控件的事件响应,这里是Textbox的 textchange。
2. 另外,我看了一些帖子应该是用sender来判断,问题是界面上还计划加入其他的Textbox来实现数据条件筛选的功能。这样可能会有点混乱。
下面是代码
程序代码:
Public Class Form1 …… Dim TxtFlds As New ArrayList Dim LabelFlds As New ArrayList ……
程序代码:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim n As Integer n = 0 For i = 0 To DataGridView1.Columns.Count - 1 '动态增加Label Dim lblControl As New Label lblControl.Location = New Point(550, n * 50 + 50) Me.Controls.Add(lblControl) LabelFlds.Add(lblControl) lblControl.Text = DataGridView1.Columns(n).Name '动态增加textbox Dim TxtControl As New TextBox TxtControl.Location = New Point(650, n * 50 + 50) Me.Controls.Add(TxtControl) TxtControl.Text = "" TxtControl.ReadOnly = True TxtFlds.Add(TxtControl) n += 1 Next i DataStatus = “readonly” Call DataGridView1_CellClick(Nothing, Nothing) End Sub
程序代码:
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick For j = 0 To TxtFlds.Count - 1 TxtFlds(j).Text = "" On Error Resume Next TxtFlds(j).Text = DataGridView1.Item(n, DataGridView1.CurrentCell.RowIndex).Value n += 1 Next j DataStatus = ss End Sub