Articles in this section
Category / Section

How to add a Windows Forms GridControl in Visual Basic 6.0?

2 mins read

To add a Windows Forms grid control in Visual Basic 6.0 we should follow the below steps.

Step 1: Create new WF library project.

Step 2: Add form and necessary control to the project.

Step 3: Include below class libraries for InterOp functions.

Adding InterOP function

using System.Runtime.InteropServices;
using System.Text;
using System.Reflection;
using Microsoft.Win32;

Step 4:  Need to register Com objects, below code snippet in class file for com registration.

Com file

 

[ComRegisterFunction()]
public static void RegisterClass ( string key )
{
StringBuilder      sb = new StringBuilder ( key ) ;
sb.Replace(@"HKEY_CLASSES_ROOT\","") ;
RegistryKey k    = Registry.ClassesRoot.OpenSubKey(sb.ToString(),true);
RegistryKey ctrl = k.CreateSubKey ( "Control" ) ;
ctrl.Close ( ) ;
RegistryKey inprocServer32 = k.OpenSubKey ( "InprocServer32" , true )  ;
inprocServer32.SetValue ( "CodeBase" ,Assembly.GetExecutingAssembly().CodeBase );
inprocServer32.Close ( ) ;
k.Close (  ) ;
}
[ComUnregisterFunction()]
public static void UnregisterClass ( string key  )
{
StringBuilder  sb = new StringBuilder ( key ) ;
sb.Replace(@"HKEY_CLASSES_ROOT\","") ;
RegistryKey  k =  Registry.ClassesRoot.OpenSubKey(sb.ToString(),true);
k.DeleteSubKey ( "Control" , false ) ;
RegistryKey  inprocServer32 = k.OpenSubKey (  "InprocServer32" , true   ) ;
k.DeleteSubKey ( "CodeBase", false ) ;
k.Close( );
}

Step 5:  Need to check COM object visibility in Properties -> Application -> Assembly Information -> Check Make assembly COM – visible.

Step 6:  Need to check register for COM interop via Properties -> Build -> Register for COM interop.

Step 7:  Rebuild the application and generate project assembly.

Step 8: Open visual studio command prompt as administrator. And execute below command.

Regasm “Assembly file path”  for example [“C:/GaugeWF.dll”]
regasm “Assembly file path” /regfile:GaugeWF.reg
regasm “Assembly file path” /tlb: GaugeWF.tlb
regasm  /codebase “Assembly file path”

By following above steps generated assembly will be registered in local machine and so it will be exposed as ActiveX control. And it can have tested via opening it in VS ActiveX control test container.

Step 9: For testing functionality, Open Active-X test container in below location.

C:\Program Files (x86) \Microsoft Visual Studio 8\Common7\Tools\tstcon32.exe

Step 10: Select Edit -> Add New Control -> above control will be available in this location and by double clicking on it, that will be integrated in VBA container.

 

Showing Grid control in Visual Basic

Sample:

VB: Windows forms grid control in VB6.0

Video:

Windows forms grid control in VB6.0

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied