|
-
Jan 21st, 2011, 08:57 AM
#1
Thread Starter
Member
Please Help w/ getting controls from Tabpages
I've hit a roadblock and really need help with looping through tabconrol's tabpage's, getting each tabpage's parent name and richtextbox control's text value. I have a ctabcontrol that has ctabpage tabpages, which also have Usercontrol's on the body of each tab. I developed a FindAll to search through each openned tabpage's richtextbox in the mdi parent container form. However, I cannot get the for loop to produce any values for the controls. All values are 0. The richtextbox.text value is empty. I even tried to produce a value with TabControlCollection to no avail, it shows 0 tabs in the collection even though I have 3 tabs open in the mdi parent container. How can I get the actual controls and values from other tabs so I can evaluate them in my Find tabpage functons?
Code:
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tabCtrl As New cTabControl
Dim frmMain As New frmMain
Dim x As New Integer
x = frmMain.tabCtrl.TabCount
wordToFind = Trim(tbwordtofind.Text.ToString)
Occurences = 0
' NOTE: The tabCtrl is not getting the TabPages or TabPageCollection to populate values
Dim TabCollection As TabControl.TabPageCollection = tabCtrl.TabPages
' Check if an entry is in the Find textbox or if it is empty
If FindForm_Validation() = True Then
Dim Pdf As New Pdf
Dim Pdfrtb As RichTextBox = Pdf.RichTextBox1
' Use the richtextbox's find feature for the form currently in focus (being used)
If wordToFind.Length > 0 Then
tbOccurenceCount.Text = Me.FindAll(0, wordToFind, Pdfrtb)
End If
' If the Text Form is open
Dim Taxonomy As New Taxonomy
Dim Taxrtb As RichTextBox = Taxonomy.RichTextBox1
' Do the same for the text form if it is open (focused)
If wordToFind.Length > 0 Then
tbOccurenceCount.Text = Me.FindAll(0, wordToFind, Taxrtb)
End If
' If the Text Form is open
Dim Text As New Text
Dim Textrtb As RichTextBox = Text.RichTextBox1
' Do the same for the text form if it is open (focused)
If wordToFind.Length > 0 Then
tbOccurenceCount.Text = Me.FindAll(0, wordToFind, Textrtb)
End If
End If
End Sub
-
Jan 21st, 2011, 09:13 AM
#2
Thread Starter
Member
Re: Please Help w/ getting controls from Tabpages
I also tried the following code example, which didn't work either:
Code:
For Each ctr As Control In tabcontrolname.Controls
For Each ctr1 As Control In ctr.Controls
If TypeOf ctr1 Is Tabpage Then
Dim pdf As Form = ctr1.FindForm()
Pdf.Richtextbox1.Text = ""
End If
Next
Next
-
Jan 21st, 2011, 12:29 PM
#3
Re: Please Help w/ getting controls from Tabpages
The loop you have in the second post isn't correct:
vb.net Code:
'//for the code to work as expected you can't have the RichTextBox controls '//in any other parent containers such as a Panel, GroupBox etc... For Each page As TabPage In Me.TabControl1.TabPages For Each ctl As Control In page.Controls If TypeOf ctl Is RichTextBox Then MessageBox.Show(ctl.Text) End If Next Next
-
Jan 22nd, 2011, 08:36 PM
#4
Thread Starter
Member
Re: Please Help w/ getting controls from Tabpages
The code works, partially. It finds the richtextbox control on the tabpage but it's text value is empty. How can I get the text, and other properties, from the richtextbox control on the tabpage? I need to access the richtextbox from other usercontrols on thier individual tabpage for save, find, etc. functions in my application. Thanks, I really appreciate your help.
Code:
For Each tabctl As Control In Me.Controls
' This one references usercontrols
For Each ctl As Control In tabctl.Controls
' This one references the richtextbox in the respective usercontrol
If TypeOf ctl Is RichTextBox Then
MessageBox.Show(ctl.Text)
End If
Next
Next
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|