如何在vb.net的控制名称中连接变量整数 [英] How to concat variable integer in control name in vb.net
本文介绍了如何在vb.net的控制名称中连接变量整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
来循环
来浏览每个组框和单选按钮。这是我的代码:$ p $
Dim sqlda As New SqlDataAdapter(SELECT * FROM table1 WHERE column1 ='& lblWONo。 Text&',Constr)
Dim sqlds As New DataSet
sqlds.Clear()
sqlda.Fill(sqlds)
sqlds.Tables(0).Rows.Count> 0 Then
With sqlds.Tables(0).DefaultView.Item(0)
txtDateCreated.Value = .Item(0).ToString
txtComments.Text = .Item(1).ToString
'检查列是否包含FALSE / TRUE值
'然后切换单选按钮状态为TRUE
'在这部分我知道有另一个/最简单的方法来检查单选按钮真值
',这是我的代码使用循环(下面):
如果.Item(2)= False那么
rdbtn1No.Checked = True
Else
rdbtn1Yes.Checked = True
End If
如果.Item(3)= False则
rdbtn2No。 Checked = True
Else
rdbtn2Yes.Checked = True
End If
如果.Item(4)= False那么
opt3N.Checked = True
其他
op t3Y.Checked = True
End If
End With
End If
< LOOPING的示例代码:
Dim itemNo As Integer
Dim rdbtnSet As Integer = 1
Dim grpboxCnt As Integer = 1
对于每个grpbx作为GroupBox在Me.Controls.OfType(GroupBox)()
对于itemNo = 2到sqlds.Tables(0).Columns.Count
如果.Item(itemNo)= True那么
rdbtn& rdbtnSet& 是的.checked = True我想这样,但是我们知道这是行不通的,或者它不是正确的方式。这是我的问题。
其他
rdbtn& rdbtnSet& No.checked = True'我想这样,但是我们知道这不是工作,或者它不是正确的方式。这是我的问题。
结束如果
下一个
rdbtnSet + = 1
grpboxCnt + = 1
下一个
就是这样。先谢谢你!考虑使用字典(id,control)来存储你的控件。然后迭代字典并设置你的状态。
Now I have a database and pull out that data and display it to form,i have a sequence of groupbox and radiobuttons, in each groupbox (groupbox1,groupbox2,etc...) there are 2 radio buttons namely rdbtn1Yes and rdbtn1No (then it increment +1 in next Groupbox). now i use for loop
to go through every groupboxes and radio buttons. And this is my code:
Dim sqlda As New SqlDataAdapter("SELECT * FROM table1 WHERE column1= '" & lblWONo.Text & "'", Constr)
Dim sqlds As New DataSet
sqlds.Clear()
sqlda.Fill(sqlds)
If sqlds.Tables(0).Rows.Count > 0 Then
With sqlds.Tables(0).DefaultView.Item(0)
txtDateCreated.Value = .Item(0).ToString
txtComments.Text = .Item(1).ToString
'check column if it contain FALSE/TRUE value
'then toggle the radiobutton state to TRUE
'In this part i know there is another/easiest way to checked radio buttons to TRUE value
'and this is my code using looping (below):
If .Item(2) = False Then
rdbtn1No.Checked = True
Else
rdbtn1Yes.Checked = True
End If
If .Item(3) = False Then
rdbtn2No.Checked = True
Else
rdbtn2Yes.Checked = True
End If
If .Item(4) = False Then
opt3N.Checked = True
Else
opt3Y.Checked = True
End If
End With
End If
SAMPLE CODE FOR LOOPING:
Dim itemNo As Integer
Dim rdbtnSet As Integer = 1
Dim grpboxCnt As Integer = 1
For Each grpbx As GroupBox In Me.Controls.OfType(Of GroupBox)()
For itemNo = 2 To sqlds.Tables(0).Columns.Count
If .Item(itemNo) = True Then
rdbtn & rdbtnSet & "Yes".checked = True 'I want to be this way but we know that this is not working or its not the proper way. That is my problem.
Else
rdbtn & rdbtnSet & "No".checked = True 'I want to be this way but we know that this is not working or its not the proper way. That is my problem.
End If
Next
rdbtnSet += 1
grpboxCnt += 1
Next
Thats all. Thank you in advance!
解决方案
Think about the use of a dictionary (id, control) to store your controls. Then iterate the dictionary and set your state.
这篇关于如何在vb.net的控制名称中连接变量整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文