Link to home
Start Free TrialLog in
Avatar of Peter Allen
Peter AllenFlag for United States of America

asked on

Exposing DataGridView properties in a Class in VB.NET 2013

I have the following code in VB.NET 2008 which works just fine.  However, when I port this code into VB.NET 2013 project the DataGridView reference doesn't exist.

Public Function fncInitializeDataGridView_GenerateControl _
           ( _

           ByRef oDataGridView As DataGridView, _
           ByRef dsDataSet As DataSet _
           ) _
            As DataGridView
        'Function Parameter Variables
        '  oDataGridView  DataGridView Control from Form
        '  dsDataSet      DataSet containing DataGridView datatable(s)
        'Function General Variables
        ' sFormName       Form Name
        ' sCtrlName       Control Name
        'Function Returns DataGridView Control
        Dim sFormName As String = oDataGridView.Parent.Name
        Dim sCtrlName As String = oDataGridView.Name
        Call fncInitializeDataGridView_ControlSetup(oDataGridView, dsTempTables)
        Call fncInitializeDataGridView_ControlProperties(oDataGridView)
        Call fncInitializeDataGridView_ControlColumnSetup(oDataGridView, dsDataSet)
        oclsDataGridView_XMLProcessing.subSaveDataGridViewXMLSettings(sFormName, sCtrlName)
        If dsDataSet.Tables.Count > 0 Then
            Call subBuildTables_InitializeTempDataSet(dsDataSet)
            Call subBuildTables_InitializeDataGridView(oDataGridView)
            Call subBuildDGView_PopulateTempDataSet(dsDataSet, dsTempTables)
            Call subBuildDGView_PopulateDataGridView(oDataGridView, dsTempTables)
        End If
        Return oDataGridView
    End Function

Open in new window

I get a "syntax error on the first "Byref" and the "Return oDataGridView" lines.  In VB.NET 2008 the DataGridView was available, but in VB.NET 2013 it is somewhere else which makes me think that I have to add references to the class.  Would this be correct?  

Thanks for your assistance.
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nothing has changed with the DataGridView class, it still a member of the System.Windows.Forms namespace.

As Fernando pointed out, if your code is a direct copy-paste, you have a space between the parentheses line and the ByRef line.User generated imageUser generated imageUser generated image
Avatar of Peter Allen


Well shoot.  I neglected that obvious error.  Thank you Fernando.

The only issue I have now to resolve is a message that indicates that DataGridView in the line...

"ByRef oDataGridView as DataGridView" gives the error as "Type 'DataGridView' not defined".  This code is in a Class I am using which is compiled in a Class Library DLL in 2008.  I am going to do the same in 2013.

To define the type I tried adding Systep.Winsows.Forms before DataGridView and that didn't work.  I am reviewing now what Resources are setup to work with the code in 2008 to see if it differs from 2013.

Any further suggestions?
Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I just compared the references for the library.  They are now identicle, but I still get a "DataGridView" type not defined.
Are you missing an Import for System.Windows.Forms.  If you do not have an explicit import line for System.Windows.Forms in the original code file, the import can be explicitly defined for all code files in your project.

1.  Right click the original project and choose properties.
2.  Go to the references tab.
3.  Look through the Imported namespaces to see if there is a checkbox next to System.Windows.Forms.User generated image
This setting though, can be both a curse and a blessing.  Right now, you are witnessing one of the curse aspects.  ;)

Try to give the fullname: ByVal oDataGridView As System.Windows.Forms.DataGridView.

Note that I use ByVal instead of ByRef. It would not solve your problem, because for what you are doing, ByRef and ByVal end up doing the exact same thing. But the way you use ByRef is a very common mistake. It usually has no impact, but might if you are not aware of what happens.

The difference between ByRef and ByVal as most programmers understand it is meaningful only for value objects (structures and primitive types). There is also a difference between ByRef and ByVal with reference objects (based on a class), but it has very little use, and this can lead to what appears as strange behavior.

When you pass a reference object, you do not have to pass it ByRef. Reference objects are already a reference. Your variable is not the object, your variable is only a pointer to the memory space occupied by the object. Passing normally (ByVal) is sufficient, because you are passing the pointer. So when the called method works with the parameter, it works with the same memory address and changes the values in the object the same way as if you have passed it ByRef.

Another way to explain this is when you pass a value object ByVal, you copy its value. When you pass a reference object ByVal, you pass a copy of its pointer, that is of its address in memory, so ending up having the same effect as passing it ByRef.

So, basically, it makes no difference. But, there is a slim danger when you pass a reference object ByRef if your are not aware of this. By mistake, you could replace the object that the variable points to by another one. In such a situation, any change you would make to a property or any method you would called would not be on the object that was passed.

Give a look at the table at the end of the documentation page.
Thank you very much!  Boy do I feel dumb sometimes.  GRIN.  I should have seen this regarding the IMPORTS statement  That did the trick along with ensuring that the References were updated.

There are references for the application and then there are IMPORTS.  I am still a bit confused because I have the Reference checked for System.Windows.Forms and then had to add the IMPORTS too.

Can you explain this to me.  To this day I still get confused as to why I need both (or do I)?
References essentially indicate a dependency to the CLR.  Imports (in VB) and Usings (in C#) indicate where the dependency is used.

In reality though, the imports/usings are allowed for the benefit of the developer as the compiler replaces the implied usage with the explicit reference.  I say for the benefit of the developer because the imports/usings allow for you to say to the designer, "If I call or declare a class/method/property defined here I want to use it."

In your case the class is the DataGridView.

I am not in front of a computer right now, so I cannot provide an example IL output to show how the CLR replaces the imported/used implicit definition with an explicit definition.

It is also important to note that the CLR does the same when encountering an implied variable declaration.
Dim i = 0

Open in new window

Implies that an integer is declared as i.

Now that I am in front of a computer.  For more on what I was referring to.  Take the following code:
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms

Public Class Form1
	Private people As List(Of Person)

	Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
		Dim i = 0
		people = New List(Of Person) From _
		 { _
		  New Person() With {.ID = 1, .Name = "Peter"}, _
		  New Person() With {.ID = 2, .Name = "Paul"}, _
		  New Person() With {.ID = 3, .Name = "Mary"} _
		DataGridView1.DataSource = people
		PrintPeople(DataGridView1, i)
	End Sub

	Private Sub PrintPeople(ByVal dgv As DataGridView, ByVal num As Integer)
		num = dgv.Rows.Count
		MessageBox.Show(String.Format("There are {0} rows in the datagrid.", num))
		For Each row In dgv.Rows
			If TypeOf row.DataBoundItem Is Person Then
				Dim person = DirectCast(row.DataBoundItem, Person)
				MessageBox.Show(String.Format("ID = {0}, Name = {1}", person.ID, person.Name))
			End If
	End Sub
End Class

Class Person
	Public Property ID() As Integer
	Public Property Name() As String
End Class

Open in new window

Now let's look at what the compiler does when building this into IL.User generated imageAnd here is the compiled IL code. -
.namespace EE_Q28584003
    .class public auto ansi beforefieldinit Form1
        extends [System.Windows.Forms]System.Windows.Forms.Form
        .custom instance void [Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.DesignerGeneratedAttribute::.ctor()
        .method private specialname rtspecialname static void .cctor() cil managed
            .custom instance void [mscorlib]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor()
            .maxstack 8
            L_0000: newobj instance void [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference>::.ctor()
            L_0005: stsfld class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> EE_Q28584003.Form1::__ENCList
            L_000a: nop 
            L_000b: ret 

        .method public specialname rtspecialname instance void .ctor() cil managed
            .custom instance void [mscorlib]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor()
            .maxstack 8
            L_0000: ldarg.0 
            L_0001: call instance void [System.Windows.Forms]System.Windows.Forms.Form::.ctor()
            L_0006: nop 
            L_0007: ldarg.0 
            L_0008: ldarg.0 
            L_0009: dup 
            L_000a: ldvirtftn instance void EE_Q28584003.Form1::Form1_Load(object, class [mscorlib]System.EventArgs)
            L_0010: newobj instance void [mscorlib]System.EventHandler::.ctor(object, native int)
            L_0015: call instance void [System.Windows.Forms]System.Windows.Forms.Form::add_Load(class [mscorlib]System.EventHandler)
            L_001a: nop 
            L_001b: ldarg.0 
            L_001c: call void EE_Q28584003.Form1::__ENCAddToList(object)
            L_0021: nop 
            L_0022: ldarg.0 
            L_0023: callvirt instance void EE_Q28584003.Form1::InitializeComponent()
            L_0028: nop 
            L_0029: nop 
            L_002a: ret 

        .method private static void __ENCAddToList(object 'value') cil managed
            .custom instance void [mscorlib]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor()
            .maxstack 4
            .locals init (
                [0] int32 num,
                [1] int32 num2,
                [2] class [mscorlib]System.WeakReference reference,
                [3] class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> list,
                [4] int32 num3,
                [5] bool flag,
                [6] bool flag2,
                [7] int32 num4)
            L_0000: nop 
            L_0001: ldsfld class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> EE_Q28584003.Form1::__ENCList
            L_0006: stloc.3 
            L_0007: ldloc.3 
            L_0008: call void [mscorlib]System.Threading.Monitor::Enter(object)
            L_000d: nop 
            L_000e: nop 
            L_000f: ldsfld class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> EE_Q28584003.Form1::__ENCList
            L_0014: callvirt instance int32 [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference>::get_Count()
            L_0019: ldsfld class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> EE_Q28584003.Form1::__ENCList
            L_001e: callvirt instance int32 [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference>::get_Capacity()
            L_0023: ceq 
            L_0025: stloc.s flag
            L_0027: ldloc.s flag
            L_0029: brfalse L_00bf
            L_002e: ldc.i4.0 
            L_002f: stloc.0 
            L_0030: ldc.i4.0 
            L_0031: ldsfld class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> EE_Q28584003.Form1::__ENCList
            L_0036: callvirt instance int32 [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference>::get_Count()
            L_003b: ldc.i4.1 
            L_003c: sub.ovf 
            L_003d: stloc.s num3
            L_003f: stloc.1 
            L_0040: br.s L_0089
            L_0042: ldsfld class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> EE_Q28584003.Form1::__ENCList
            L_0047: ldloc.1 
            L_0048: callvirt instance !0 [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference>::get_Item(int32)
            L_004d: stloc.2 
            L_004e: ldloc.2 
            L_004f: callvirt instance bool [mscorlib]System.WeakReference::get_IsAlive()
            L_0054: stloc.s flag
            L_0056: ldloc.s flag
            L_0058: brfalse.s L_0083
            L_005a: ldloc.1 
            L_005b: ldloc.0 
            L_005c: ceq 
            L_005e: ldc.i4.0 
            L_005f: ceq 
            L_0061: stloc.s flag2
            L_0063: ldloc.s flag2
            L_0065: brfalse.s L_007e
            L_0067: ldsfld class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> EE_Q28584003.Form1::__ENCList
            L_006c: ldloc.0 
            L_006d: ldsfld class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> EE_Q28584003.Form1::__ENCList
            L_0072: ldloc.1 
            L_0073: callvirt instance !0 [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference>::get_Item(int32)
            L_0078: callvirt instance void [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference>::set_Item(int32, !0)
            L_007d: nop 
            L_007e: nop 
            L_007f: ldloc.0 
            L_0080: ldc.i4.1 
            L_0081: add.ovf 
            L_0082: stloc.0 
            L_0083: nop 
            L_0084: nop 
            L_0085: ldloc.1 
            L_0086: ldc.i4.1 
            L_0087: add.ovf 
            L_0088: stloc.1 
            L_0089: ldloc.1 
            L_008a: ldloc.s num3
            L_008c: stloc.s num4
            L_008e: ldloc.s num4
            L_0090: ble.s L_0042
            L_0092: ldsfld class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> EE_Q28584003.Form1::__ENCList
            L_0097: ldloc.0 
            L_0098: ldsfld class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> EE_Q28584003.Form1::__ENCList
            L_009d: callvirt instance int32 [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference>::get_Count()
            L_00a2: ldloc.0 
            L_00a3: sub.ovf 
            L_00a4: callvirt instance void [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference>::RemoveRange(int32, int32)
            L_00a9: nop 
            L_00aa: ldsfld class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> EE_Q28584003.Form1::__ENCList
            L_00af: ldsfld class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> EE_Q28584003.Form1::__ENCList
            L_00b4: callvirt instance int32 [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference>::get_Count()
            L_00b9: callvirt instance void [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference>::set_Capacity(int32)
            L_00be: nop 
            L_00bf: nop 
            L_00c0: ldsfld class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> EE_Q28584003.Form1::__ENCList
            L_00c5: ldarg.0 
            L_00c6: call object [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::GetObjectValue(object)
            L_00cb: newobj instance void [mscorlib]System.WeakReference::.ctor(object)
            L_00d0: callvirt instance void [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference>::Add(!0)
            L_00d5: nop 
            L_00d6: nop 
            L_00d7: leave.s L_00e2
            L_00d9: nop 
            L_00da: ldloc.3 
            L_00db: call void [mscorlib]System.Threading.Monitor::Exit(object)
            L_00e0: nop 
            L_00e1: endfinally 
            L_00e2: nop 
            L_00e3: nop 
            L_00e4: ret 
            .try L_000f to L_00d9 finally handler L_00d9 to L_00e2

        .method family virtual instance void Dispose(bool disposing) cil managed
            .custom instance void [mscorlib]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor()
            .maxstack 2
            .locals init (
                [0] bool VB$CG$t_bool$S0)
            L_0000: nop 
            L_0001: nop 
            L_0002: ldarg.1 
            L_0003: brfalse.s L_000d
            L_0005: ldarg.0 
            L_0006: ldfld class [System]System.ComponentModel.IContainer EE_Q28584003.Form1::components
            L_000b: brtrue.s L_0010
            L_000d: ldc.i4.0 
            L_000e: br.s L_0011
            L_0010: ldc.i4.1 
            L_0011: stloc.0 
            L_0012: ldloc.0 
            L_0013: brfalse.s L_0021
            L_0015: ldarg.0 
            L_0016: ldfld class [System]System.ComponentModel.IContainer EE_Q28584003.Form1::components
            L_001b: callvirt instance void [mscorlib]System.IDisposable::Dispose()
            L_0020: nop 
            L_0021: nop 
            L_0022: leave.s L_002e
            L_0024: nop 
            L_0025: ldarg.0 
            L_0026: ldarg.1 
            L_0027: call instance void [System.Windows.Forms]System.Windows.Forms.Form::Dispose(bool)
            L_002c: nop 
            L_002d: endfinally 
            L_002e: nop 
            L_002f: nop 
            L_0030: ret 
            .try L_0002 to L_0024 finally handler L_0024 to L_002e

        .method private instance void Form1_Load(object sender, class [mscorlib]System.EventArgs e) cil managed
            .maxstack 4
            .locals init (
                [0] int32 i,
                [1] class [mscorlib]System.Collections.Generic.List`1<class EE_Q28584003.Person> VB$t_ref$S0,
                [2] class EE_Q28584003.Person VB$t_ref$S1,
                [3] class EE_Q28584003.Person VB$t_ref$S2,
                [4] class EE_Q28584003.Person VB$t_ref$S3)
            L_0000: nop 
            L_0001: ldc.i4.0 
            L_0002: stloc.0 
            L_0003: ldarg.0 
            L_0004: newobj instance void [mscorlib]System.Collections.Generic.List`1<class EE_Q28584003.Person>::.ctor()
            L_0009: stloc.1 
            L_000a: ldloc.1 
            L_000b: newobj instance void EE_Q28584003.Person::.ctor()
            L_0010: stloc.2 
            L_0011: ldloc.2 
            L_0012: ldc.i4.1 
            L_0013: callvirt instance void EE_Q28584003.Person::set_ID(int32)
            L_0018: nop 
            L_0019: ldloc.2 
            L_001a: ldstr "Peter"
            L_001f: callvirt instance void EE_Q28584003.Person::set_Name(string)
            L_0024: nop 
            L_0025: ldloc.2 
            L_0026: callvirt instance void [mscorlib]System.Collections.Generic.List`1<class EE_Q28584003.Person>::Add(!0)
            L_002b: nop 
            L_002c: ldloc.1 
            L_002d: newobj instance void EE_Q28584003.Person::.ctor()
            L_0032: stloc.3 
            L_0033: ldloc.3 
            L_0034: ldc.i4.2 
            L_0035: callvirt instance void EE_Q28584003.Person::set_ID(int32)
            L_003a: nop 
            L_003b: ldloc.3 
            L_003c: ldstr "Paul"
            L_0041: callvirt instance void EE_Q28584003.Person::set_Name(string)
            L_0046: nop 
            L_0047: ldloc.3 
            L_0048: callvirt instance void [mscorlib]System.Collections.Generic.List`1<class EE_Q28584003.Person>::Add(!0)
            L_004d: nop 
            L_004e: ldloc.1 
            L_004f: newobj instance void EE_Q28584003.Person::.ctor()
            L_0054: stloc.s VB$t_ref$S3
            L_0056: ldloc.s VB$t_ref$S3
            L_0058: ldc.i4.3 
            L_0059: callvirt instance void EE_Q28584003.Person::set_ID(int32)
            L_005e: nop 
            L_005f: ldloc.s VB$t_ref$S3
            L_0061: ldstr "Mary"
            L_0066: callvirt instance void EE_Q28584003.Person::set_Name(string)
            L_006b: nop 
            L_006c: ldloc.s VB$t_ref$S3
            L_006e: callvirt instance void [mscorlib]System.Collections.Generic.List`1<class EE_Q28584003.Person>::Add(!0)
            L_0073: nop 
            L_0074: ldloc.1 
            L_0075: stfld class [mscorlib]System.Collections.Generic.List`1<class EE_Q28584003.Person> EE_Q28584003.Form1::people
            L_007a: ldarg.0 
            L_007b: callvirt instance class [System.Windows.Forms]System.Windows.Forms.DataGridView EE_Q28584003.Form1::get_DataGridView1()
            L_0080: ldarg.0 
            L_0081: ldfld class [mscorlib]System.Collections.Generic.List`1<class EE_Q28584003.Person> EE_Q28584003.Form1::people
            L_0086: callvirt instance void [System.Windows.Forms]System.Windows.Forms.DataGridView::set_DataSource(object)
            L_008b: nop 
            L_008c: ldarg.0 
            L_008d: ldarg.0 
            L_008e: callvirt instance class [System.Windows.Forms]System.Windows.Forms.DataGridView EE_Q28584003.Form1::get_DataGridView1()
            L_0093: ldloc.0 
            L_0094: callvirt instance void EE_Q28584003.Form1::PrintPeople(class [System.Windows.Forms]System.Windows.Forms.DataGridView, int32)
            L_0099: nop 
            L_009a: nop 
            L_009b: ret 

        .method private instance void InitializeComponent() cil managed
            .custom instance void [mscorlib]System.Diagnostics.DebuggerStepThroughAttribute::.ctor()
            .maxstack 4
            .locals init (
                [0] valuetype [System.Drawing]System.Drawing.Point VB$t_struct$N0,
                [1] valuetype [System.Drawing]System.Drawing.Point VB$t_struct$S1,
                [2] valuetype [System.Drawing]System.Drawing.Size VB$t_struct$N2,
                [3] valuetype [System.Drawing]System.Drawing.Size VB$t_struct$S3,
                [4] valuetype [System.Drawing]System.Drawing.SizeF VB$t_struct$N4,
                [5] valuetype [System.Drawing]System.Drawing.SizeF VB$t_struct$S5)
            L_0000: nop 
            L_0001: ldarg.0 
            L_0002: newobj instance void [System.Windows.Forms]System.Windows.Forms.DataGridView::.ctor()
            L_0007: callvirt instance void EE_Q28584003.Form1::set_DataGridView1(class [System.Windows.Forms]System.Windows.Forms.DataGridView)
            L_000c: nop 
            L_000d: ldarg.0 
            L_000e: callvirt instance class [System.Windows.Forms]System.Windows.Forms.DataGridView EE_Q28584003.Form1::get_DataGridView1()
            L_0013: callvirt instance void [System]System.ComponentModel.ISupportInitialize::BeginInit()
            L_0018: nop 
            L_0019: ldarg.0 
            L_001a: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::SuspendLayout()
            L_001f: nop 
            L_0020: ldarg.0 
            L_0021: callvirt instance class [System.Windows.Forms]System.Windows.Forms.DataGridView EE_Q28584003.Form1::get_DataGridView1()
            L_0026: ldc.i4.2 
            L_0027: callvirt instance void [System.Windows.Forms]System.Windows.Forms.DataGridView::set_ColumnHeadersHeightSizeMode(valuetype [System.Windows.Forms]System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode)
            L_002c: nop 
            L_002d: ldarg.0 
            L_002e: callvirt instance class [System.Windows.Forms]System.Windows.Forms.DataGridView EE_Q28584003.Form1::get_DataGridView1()
            L_0033: ldloca.s VB$t_struct$S1
            L_0035: ldc.i4.s 13
            L_0037: ldc.i4.s 13
            L_0039: call instance void [System.Drawing]System.Drawing.Point::.ctor(int32, int32)
            L_003e: nop 
            L_003f: ldloc.1 
            L_0040: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Location(valuetype [System.Drawing]System.Drawing.Point)
            L_0045: nop 
            L_0046: ldarg.0 
            L_0047: callvirt instance class [System.Windows.Forms]System.Windows.Forms.DataGridView EE_Q28584003.Form1::get_DataGridView1()
            L_004c: ldstr "DataGridView1"
            L_0051: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Name(string)
            L_0056: nop 
            L_0057: ldarg.0 
            L_0058: callvirt instance class [System.Windows.Forms]System.Windows.Forms.DataGridView EE_Q28584003.Form1::get_DataGridView1()
            L_005d: ldloca.s VB$t_struct$S3
            L_005f: ldc.i4 0x17d
            L_0064: ldc.i4 0xed
            L_0069: call instance void [System.Drawing]System.Drawing.Size::.ctor(int32, int32)
            L_006e: nop 
            L_006f: ldloc.3 
            L_0070: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Size(valuetype [System.Drawing]System.Drawing.Size)
            L_0075: nop 
            L_0076: ldarg.0 
            L_0077: callvirt instance class [System.Windows.Forms]System.Windows.Forms.DataGridView EE_Q28584003.Form1::get_DataGridView1()
            L_007c: ldc.i4.0 
            L_007d: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_TabIndex(int32)
            L_0082: nop 
            L_0083: ldarg.0 
            L_0084: ldloca.s VB$t_struct$S5
            L_0086: ldc.r4 6
            L_008b: ldc.r4 13
            L_0090: call instance void [System.Drawing]System.Drawing.SizeF::.ctor(float32, float32)
            L_0095: nop 
            L_0096: ldloc.s VB$t_struct$S5
            L_0098: callvirt instance void [System.Windows.Forms]System.Windows.Forms.ContainerControl::set_AutoScaleDimensions(valuetype [System.Drawing]System.Drawing.SizeF)
            L_009d: nop 
            L_009e: ldarg.0 
            L_009f: ldc.i4.1 
            L_00a0: callvirt instance void [System.Windows.Forms]System.Windows.Forms.ContainerControl::set_AutoScaleMode(valuetype [System.Windows.Forms]System.Windows.Forms.AutoScaleMode)
            L_00a5: nop 
            L_00a6: ldarg.0 
            L_00a7: ldloca.s VB$t_struct$S3
            L_00a9: ldc.i4 0x196
            L_00ae: ldc.i4 0x106
            L_00b3: call instance void [System.Drawing]System.Drawing.Size::.ctor(int32, int32)
            L_00b8: nop 
            L_00b9: ldloc.3 
            L_00ba: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Form::set_ClientSize(valuetype [System.Drawing]System.Drawing.Size)
            L_00bf: nop 
            L_00c0: ldarg.0 
            L_00c1: callvirt instance class [System.Windows.Forms]System.Windows.Forms.Control/ControlCollection [System.Windows.Forms]System.Windows.Forms.Control::get_Controls()
            L_00c6: ldarg.0 
            L_00c7: callvirt instance class [System.Windows.Forms]System.Windows.Forms.DataGridView EE_Q28584003.Form1::get_DataGridView1()
            L_00cc: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control/ControlCollection::Add(class [System.Windows.Forms]System.Windows.Forms.Control)
            L_00d1: nop 
            L_00d2: ldarg.0 
            L_00d3: ldstr "Form1"
            L_00d8: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Name(string)
            L_00dd: nop 
            L_00de: ldarg.0 
            L_00df: ldstr "Form1"
            L_00e4: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Form::set_Text(string)
            L_00e9: nop 
            L_00ea: ldarg.0 
            L_00eb: callvirt instance class [System.Windows.Forms]System.Windows.Forms.DataGridView EE_Q28584003.Form1::get_DataGridView1()
            L_00f0: callvirt instance void [System]System.ComponentModel.ISupportInitialize::EndInit()
            L_00f5: nop 
            L_00f6: ldarg.0 
            L_00f7: ldc.i4.0 
            L_00f8: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::ResumeLayout(bool)
            L_00fd: nop 
            L_00fe: nop 
            L_00ff: ret 

        .method private instance void PrintPeople(class [System.Windows.Forms]System.Windows.Forms.DataGridView dgv, int32 num) cil managed
            .maxstack 7
            .locals init (
                [0] object row,
                [1] class EE_Q28584003.Person person,
                [2] class [mscorlib]System.Collections.IEnumerator VB$t_ref$L0,
                [3] bool VB$CG$t_bool$S0)
            L_0000: nop 
            L_0001: ldarg.1 
            L_0002: callvirt instance class [System.Windows.Forms]System.Windows.Forms.DataGridViewRowCollection [System.Windows.Forms]System.Windows.Forms.DataGridView::get_Rows()
            L_0007: callvirt instance int32 [System.Windows.Forms]System.Windows.Forms.DataGridViewRowCollection::get_Count()
            L_000c: starg.s num
            L_000e: ldstr "There are {0} rows in the datagrid."
            L_0013: ldarg.2 
            L_0014: box int32
            L_0019: call string [mscorlib]System.String::Format(string, object)
            L_001e: call valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string)
            L_0023: pop 
            L_0024: nop 
            L_0025: ldarg.1 
            L_0026: callvirt instance class [System.Windows.Forms]System.Windows.Forms.DataGridViewRowCollection [System.Windows.Forms]System.Windows.Forms.DataGridView::get_Rows()
            L_002b: callvirt instance class [mscorlib]System.Collections.IEnumerator [mscorlib]System.Collections.IEnumerable::GetEnumerator()
            L_0030: stloc.2 
            L_0031: br.s L_009e
            L_0033: ldloc.2 
            L_0034: callvirt instance object [mscorlib]System.Collections.IEnumerator::get_Current()
            L_0039: call object [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::GetObjectValue(object)
            L_003e: stloc.0 
            L_003f: ldloc.0 
            L_0040: ldnull 
            L_0041: ldstr "DataBoundItem"
            L_0046: ldc.i4.0 
            L_0047: newarr object
            L_004c: ldnull 
            L_004d: ldnull 
            L_004e: ldnull 
            L_004f: call object [Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.NewLateBinding::LateGet(object, class [mscorlib]System.Type, string, object[], string[], class [mscorlib]System.Type[], bool[])
            L_0054: isinst EE_Q28584003.Person
            L_0059: ldnull 
            L_005a: cgt.un 
            L_005c: stloc.3 
            L_005d: ldloc.3 
            L_005e: brfalse.s L_009c
            L_0060: ldloc.0 
            L_0061: ldnull 
            L_0062: ldstr "DataBoundItem"
            L_0067: ldc.i4.0 
            L_0068: newarr object
            L_006d: ldnull 
            L_006e: ldnull 
            L_006f: ldnull 
            L_0070: call object [Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.NewLateBinding::LateGet(object, class [mscorlib]System.Type, string, object[], string[], class [mscorlib]System.Type[], bool[])
            L_0075: castclass EE_Q28584003.Person
            L_007a: stloc.1 
            L_007b: ldstr "ID = {0}, Name = {1}"
            L_0080: ldloc.1 
            L_0081: callvirt instance int32 EE_Q28584003.Person::get_ID()
            L_0086: box int32
            L_008b: ldloc.1 
            L_008c: callvirt instance string EE_Q28584003.Person::get_Name()
            L_0091: call string [mscorlib]System.String::Format(string, object, object)
            L_0096: call valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string)
            L_009b: pop 
            L_009c: nop 
            L_009d: nop 
            L_009e: ldloc.2 
            L_009f: callvirt instance bool [mscorlib]System.Collections.IEnumerator::MoveNext()
            L_00a4: stloc.3 
            L_00a5: ldloc.3 
            L_00a6: brtrue.s L_0033
            L_00a8: nop 
            L_00a9: leave.s L_00c9
            L_00ab: ldloc.2 
            L_00ac: isinst [mscorlib]System.IDisposable
            L_00b1: ldnull 
            L_00b2: ceq 
            L_00b4: ldc.i4.0 
            L_00b5: ceq 
            L_00b7: stloc.3 
            L_00b8: ldloc.3 
            L_00b9: brfalse.s L_00c7
            L_00bb: ldloc.2 
            L_00bc: isinst [mscorlib]System.IDisposable
            L_00c1: callvirt instance void [mscorlib]System.IDisposable::Dispose()
            L_00c6: nop 
            L_00c7: nop 
            L_00c8: endfinally 
            L_00c9: nop 
            L_00ca: ret 
            .try L_0025 to L_00ab finally handler L_00ab to L_00c9

        .property instance class [System.Windows.Forms]System.Windows.Forms.DataGridView DataGridView1
            .get instance class [System.Windows.Forms]System.Windows.Forms.DataGridView EE_Q28584003.Form1::get_DataGridView1()
            .set instance void EE_Q28584003.Form1::set_DataGridView1(class [System.Windows.Forms]System.Windows.Forms.DataGridView)

        .field private static class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.WeakReference> __ENCList

        .field private class [System.Windows.Forms]System.Windows.Forms.DataGridView _DataGridView1
            .custom instance void [mscorlib]System.Runtime.CompilerServices.AccessedThroughPropertyAttribute::.ctor(string) = { string('DataGridView1') }

        .field private class [System]System.ComponentModel.IContainer components

        .field private class [mscorlib]System.Collections.Generic.List`1<class EE_Q28584003.Person> people


Open in new window -
.namespace EE_Q28584003
    .class private auto ansi Person
        extends [mscorlib]System.Object
        .method public specialname rtspecialname instance void .ctor() cil managed
            .custom instance void [mscorlib]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor()
            .maxstack 8
            L_0000: ldarg.0 
            L_0001: call instance void [mscorlib]System.Object::.ctor()
            L_0006: nop 
            L_0007: nop 
            L_0008: ret 

        .property instance int32 ID
            .get instance int32 EE_Q28584003.Person::get_ID()
            .set instance void EE_Q28584003.Person::set_ID(int32)

        .property instance string Name
            .get instance string EE_Q28584003.Person::get_Name()
            .set instance void EE_Q28584003.Person::set_Name(string)

        .field private int32 _ID
            .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor()
            .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = { int32(0) }

        .field private string _Name
            .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor()
            .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = { int32(0) }


Open in new window

Don't worry if you cannot understand much of this, the important thing to note is that the import statements have been removed and that everything has been explicitly defined.  Take for example the definition of PrintPeople.
Private Sub PrintPeople(ByVal dgv As DataGridView, ByVal num As Integer)

Open in new window

When it was written, we allowed for the designer to imply the reference because System.Windows.Forms is imported and is the only place where a DataGridView object is defined.  So the designer does not complain that it cannot find DataGridView.  When compiled into IL on the other hand.
.method private instance void PrintPeople(class [System.Windows.Forms]System.Windows.Forms.DataGridView dgv, int32 num) cil managed

Open in new window

The compiler replaces these references with explicit definitions.

I hope this clears up some of the confusion.  And raises a couple more questions.  ;)