Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
It seems this code required .Net framework 3.5, i need same equivalent in .net 2.0 framework,code is below.

VB
Dim rtb As RichTextBox = Me.Controls.OfType(Of RichTextBox)()
Posted
Updated 11-May-12 0:47am
v2
Comments
tanweer 11-May-12 6:51am    
Are you talking about Win Form or its web application?
hackerspk 11-May-12 6:52am    
winform
Manfred Rudolf Bihy 11-May-12 7:42am    
OfType does not produce a single element but rather a collection (IEnumerable) of them. See here[^].

Regards,

Manfred

1 solution

OfType does not produce a single element but rather a collection (IEnumerable) of them. See here[^].
You can reproduce the OfType extension method in .NET 2.0 along these lines:

C#
    List<RichTextBox> widgets = new List<RichTextBox>(); 
    foreach(Control control in this.Controls) 
    { 
        // If it is of type RichTextBox add it to the list 
        // In VB.NET the condition would be like: TypeOf control Is RichTextBox
        if(control is RichTextBox) 
            widgets.Add((RichTextBox)control); 
    } 
}


This example is in C#, but I hope you can understand what is going on.

Regards,

Manfred
 
Share this answer
 
v5
Comments
hackerspk 11-May-12 7:43am    
Thanks for your answer i have a little problem more.


For Each control As Control In TabControl1.SelectedTab.Controls
If TypeOf control Is RichTextBox Then
'' control.copy() '' This line is not working while the control is richtextbox
control.Focus()
End If
Next

if i add this one more line then it works
Dim rtb As RichTextBox = control
rtb.copy()
Manfred Rudolf Bihy 11-May-12 8:16am    
The secret lies in your code :). "For each control As Control" that means the variable control knows only that it's type is Control. A RichTextBox is derived from Control and has a Copy() method so when you declared the variable as RichTextBox your example worked.
Simples! :)
Sandeep Mewara 11-May-12 13:49pm    
Good answer. 5!
Wendelius 11-May-12 16:23pm    
Plain and simple! :) 5'd
VJ Reddy 11-May-12 23:28pm    
Nice answer. 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900