Click here to Skip to main content
16,005,037 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Reference to a non-shared member requires an object reference Pin
Geoff_300126-Jan-07 21:20
Geoff_300126-Jan-07 21:20 
GeneralRe: Reference to a non-shared member requires an object reference Pin
Christian Graus26-Jan-07 21:35
protectorChristian Graus26-Jan-07 21:35 
GeneralRe: Reference to a non-shared member requires an object reference Pin
Geoff_300126-Jan-07 21:52
Geoff_300126-Jan-07 21:52 
QuestionHow to chage the backcolor of Listview control Pin
Exelioindia26-Jan-07 20:42
Exelioindia26-Jan-07 20:42 
QuestionGet name of dynamic created controls. Pin
.NetRams26-Jan-07 20:23
.NetRams26-Jan-07 20:23 
Questionimage manipulation Pin
sameersk26-Jan-07 18:16
sameersk26-Jan-07 18:16 
AnswerRe: image manipulation Pin
Christian Graus26-Jan-07 21:12
protectorChristian Graus26-Jan-07 21:12 
QuestionHelp with a Generic function Pin
TwoFaced26-Jan-07 13:16
TwoFaced26-Jan-07 13:16 
I set out to write a Generic function that would find controls of a desired type and pass back an array of that type. For instance I could call the function and ask for all textbox's found on a form. However, I ran into a snag. I can test if a control is of Type T, but I have know way of converting that control to Type T. The following code shows the compromise I had to make due to this limitation.
'Returns a control array full of controls that match the desired type
Public Function ControlArray(Of T)(ByVal container As Control) As Control()
    'Controls to pass back
    Dim list As New List(Of Control)

    For Each ctrl As Control In container.Controls
        'If child control is of the desired type T then
        'add to list
        If ctrl.GetType Is GetType(T) Then list.Add(ctrl)
    Next
    'Return array
    Return list.ToArray
End Function
Ideally this function would look something like the code below. The big difference is I want to return an array of type T. But how can I possibly convert a generic control to an unknown type?
Public Function ControlArray(Of T)(ByVal container As Control) As T()
    'Controls to pass back
    Dim list As New List(Of T)

    For Each ctrl As Control In container.Controls
        'If child control is of the desired type T then
        'add to list
        If ctrl.GetType Is GetType(T) Then
            'The next statement won't compile and is the major problem I
            'need to work around
            list.Add(DirectCast(ctrl, T))
        End If

    Next
    'Return array
    Return list.ToArray
End Function

AnswerRe: Help with a Generic function Pin
Christian Graus26-Jan-07 13:25
protectorChristian Graus26-Jan-07 13:25 
GeneralRe: Help with a Generic function [modified] Pin
TwoFaced26-Jan-07 14:46
TwoFaced26-Jan-07 14:46 
GeneralRe: Help with a Generic function Pin
Christian Graus26-Jan-07 21:15
protectorChristian Graus26-Jan-07 21:15 
GeneralRe: Help with a Generic function Pin
TwoFaced26-Jan-07 21:50
TwoFaced26-Jan-07 21:50 
GeneralRe: Help with a Generic function Pin
Christian Graus26-Jan-07 22:36
protectorChristian Graus26-Jan-07 22:36 
QuestionReportViewer "Report processing has been cancelled" [modified] Pin
Kschuler26-Jan-07 9:01
Kschuler26-Jan-07 9:01 
AnswerRe: ReportViewer "Report processing has been cancelled" Pin
Kschuler19-Feb-07 5:29
Kschuler19-Feb-07 5:29 
QuestionHow to override DataGridView Pin
GWbasicProgrammer26-Jan-07 8:17
GWbasicProgrammer26-Jan-07 8:17 
AnswerRe: How to override DataGridView Pin
Christian Graus26-Jan-07 10:08
protectorChristian Graus26-Jan-07 10:08 
GeneralRe: How to override DataGridView Pin
GWbasicProgrammer29-Jan-07 7:18
GWbasicProgrammer29-Jan-07 7:18 
Questioneditable listview control header Pin
pnpfriend26-Jan-07 6:17
pnpfriend26-Jan-07 6:17 
Questionloading text from a file... Pin
Sergi2526-Jan-07 4:14
Sergi2526-Jan-07 4:14 
AnswerRe: loading text from a file... Pin
Christian Graus26-Jan-07 10:07
protectorChristian Graus26-Jan-07 10:07 
AnswerRe: loading text from a file... Pin
gladsmhe26-Jan-07 11:04
gladsmhe26-Jan-07 11:04 
AnswerRe: loading text from a file... Pin
Geoff_300127-Jan-07 1:10
Geoff_300127-Jan-07 1:10 
GeneralRe: loading text from a file... Pin
Sergi2528-Jan-07 12:09
Sergi2528-Jan-07 12:09 
QuestionDisplay an Image Pin
Central_IT26-Jan-07 4:07
Central_IT26-Jan-07 4:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.