Using Controls Collection

  • Thread starter sivaprakash.srinivasen
  • Start date
S

sivaprakash.srinivasen

Hi
Im creating customer details form in VB.Net, in that Im getting
Original Details as well as Correspondance details of customer. If both
are same then by clicking checkbox all the text of respective fields
should be filled in correspondance details textboxes. I achieved some
what like this....

Try
Dim i, i1 As Control
Dim j As New TextBox

If CheckBox1.CheckState = CheckState.Checked Then
For Each i In TabControl1.TabPages(0).Controls
If TypeOf i Is TextBox Then
j = New TextBox
If Microsoft.VisualBasic.Mid(i.Name(), Len(i.Name()),
Len(i.Name())) = "1" Then
j.Name = (Microsoft.VisualBasic.Left(i.Name,
Len(i.Name) - 1)).ToString
'i1.Name = j
'i1.Text = "Testing"
i.Text = j.Text
'MsgBox(j.Text)
End If
End If
Next
End If
Catch ex As Exception
MsgBox(ex.Message)

But my problem is even I declared "j" as control, Im not getting j.text
as result, alternatively Im getting textboxes name but not textbox.text
values.. please anyone can help....
 
C

Cor Ligthert [MVP]

Sivaprakash,

What you are doing now, is showing the text of a new textbox. That is for
sure empty.

Moreover, because that "Text" is a property of all controls, there is no
need to do any thing (casting or whatever) special for it.

You can just do (not complete your sample that is really to long to good
show the problem. Especially not because that you are using i and j which
are mostly used as standard names for indexers and not as controls)

for each ctr as control in mytabpage(0).controls
if TypeOff ctr is TextBox then
messagebox.show ctr.Text
end if
Next

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top