none
Programmatically enumerate all System Data Types RRS feed

  • Question

  • Hello

    I would like to populate a Combo with all the type names that a DataColumn can be ("System.String", "System.Boolean", etc). How can I do that without having to manually add the combo items?

    Thanks a lot.
    Saturday, June 6, 2009 7:29 PM

Answers

  • Hi ALL,

    I just tried it in the FORM_LOAD event. :-)

    This works with one ComboBox on a FORM.

    I guess my being able to read C# or C++ code is getting better. ;-)
     

    Regards,

    John


    Option Strict On
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim asm As System.Reflection.Assembly
            asm = System.Reflection.Assembly.Load("mscorlib.dll")
    
            Dim AllDataTypes() As System.Type = asm.GetTypes
            For Each t As System.Type In AllDataTypes
                If t.IsPrimitive Then
                    ComboBox1.Items.Add(t.FullName)
                End If
            Next
    
        End Sub
    End Class
    
    • Marked as answer by EMoscosoCam Sunday, June 7, 2009 4:09 AM
    Sunday, June 7, 2009 1:47 AM

All replies

  • Use this code:-

     Assembly _Asm = Assembly.Load("mscorlib.dll");
    
                Type[] _AllDataTypes = _Asm.GetTypes();
    
                foreach (Type _tempType in _AllDataTypes)
                {
                    if(_tempType.IsPrimitive)
                    comboBox1.Items.Add(_tempType.FullName);
                }


    Ganesh Ranganathan
    [Please mark the post as answer if you find it helpful]
    Saturday, June 6, 2009 7:56 PM
  • Hi Ganesh,

    Please keep C# or C++ code replies out of the Vb.Net forums
     unless you want help with code translation to Vb.Net.

    The following is my best attempt at a translation to Vb.Net.>>

            Dim asm As System.Reflection.Assembly
            asm = System.Reflection.Assembly.Load("mscorlib.dll")
    
            Dim AllDataTypes() As System.Type = asm.GetTypes
            For Each t As System.Type In AllDataTypes
                If t.IsPrimitive Then
                    ComboBox1.Items.Add(t.FullName)
                End If
            Next
    


    Regards,

    John

    Sunday, June 7, 2009 1:21 AM
  • Hi ALL,

    I just tried it in the FORM_LOAD event. :-)

    This works with one ComboBox on a FORM.

    I guess my being able to read C# or C++ code is getting better. ;-)
     

    Regards,

    John


    Option Strict On
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim asm As System.Reflection.Assembly
            asm = System.Reflection.Assembly.Load("mscorlib.dll")
    
            Dim AllDataTypes() As System.Type = asm.GetTypes
            For Each t As System.Type In AllDataTypes
                If t.IsPrimitive Then
                    ComboBox1.Items.Add(t.FullName)
                End If
            Next
    
        End Sub
    End Class
    
    • Marked as answer by EMoscosoCam Sunday, June 7, 2009 4:09 AM
    Sunday, June 7, 2009 1:47 AM
  • Oops...My bad...

    Didnt see that it was posted in the VB.NET forums...will make sure to check the forums first from now on....
    Ganesh Ranganathan
    [Please mark the post as answer if you find it helpful]
    Sunday, June 7, 2009 8:09 AM