我尝试使用以下代码将from中的MaskedTextBox控件列表分配给list msklist。但是,即使执行了下面所示的代码,索引值仍然是0。我的表单中有30个MaskedTextBox控件。
Private msklist As New List(Of MaskedTextBox)
Private msk() As MaskedTextBox
For Each ctrl In Me.Controls
If TypeOf ctrl Is MaskedTextBox Then
msklist.Add(ctrl)
End If
Next
MsgBox(msklist.Count)
ReDim msk(msklist.Count - 1)
msk = msklist.ToArray
For i = 0 To 29 Step 1
query = "SELECT * FROM allotment_table WHERE seat=@seat"
cmd.Parameters.AddWithValue("@seat", seat1(i))
cmd = New SqlCommand(query, con)
con.Open()
re = cmd.ExecuteReader
re.Read()
msk(i).Text = re("regno")
con.Close()
Next我希望将文本分配给控件的Text属性,使用使用数组msk的for循环
我需要一些建议
发布于 2013-08-22 02:19:20
试一试:
Private msklist As New List(Of MaskedTextBox)
' Loop through all controls in form
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is Panel Then
' Loop through each of the controls in the Panel
For Each panelCtrl As Control In ctrl.Controls
If TypeOf panelCtrl Is MaskedTextBox Then
msklist.Add(panelCtrl)
End If
Next
End If
Next
MsgBox(msklist.Count)
' Get the text value once and apply it to each text box
query = "SELECT * FROM allotment_table"
cmd = New SqlCommand(query, con)
con.Open()
re = cmd.ExecuteReader
re.Read()
Dim textValue As String = re("regno")
con.Close()
' Loop through the list of masked text boxes and apply the text value to each
For Each mskTextBox As MaskedTextBox In msklist
mskTextBox.Text = textValue
Nexthttps://stackoverflow.com/questions/18370478
复制相似问题