Hello,
I need to design a full funcionaly ActiveX Data Grid.
I created an C# project:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
using Microsoft.Win32;
namespace ActiveXGrid
{
[Guid("2DC138F0-1CB1-4F9A-ACC4-C3A1F708C495")]
public interface ItabelenForm //: ITreeViewEvents_Event
{
void Add(params object[] values);
void AddEmptyLine();
void AddEmptyColumn();
string Get(int row, int cell);
}
[Guid("A798EE8C-9EB0-40F9-A075-506FDBB149E8")]
[TypeLibType(4224)]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface tabelenFormEvents
{
[DispId(1)]
void Click();
}
[ProgId("tabelenFormTEST")]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(tabelenFormEvents))]
public partial class tabelenForm : UserControl, ItabelenForm
{
public tabelenForm()
{
InitializeComponent();
base.Click += new EventHandler(CSActiveXCtrl_Click);
}
public void Add(params object[] values)
{
tabele.Rows.Add(values);
}
public void AddEmptyLine()
{
tabele.Rows.Add();
}
public void AddEmptyColumn()
{
tabele.Columns.Add("testCol", "TCol");
}
public string Get(int row, int cell)
{
return tabele.Rows[row].Cells[cell].Value.ToString();
}
#region register
/// <summary>
/// Register the class as a control and set it's CodeBase entry
/// </summary>
/// <param name="key">The registry key of the control</param>
[ComRegisterFunction()]
public static void RegisterClass(string key)
{
// Strip off HKEY_CLASSES_ROOT\ from the passed key as I don't need it
StringBuilder sb = new StringBuilder(key);
sb.Replace(@"HKEY_CLASSES_ROOT\", "");
// Open the CLSID\{guid} key for write access
RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);
// And create the 'Control' key - this allows it to show up in
// the ActiveX control container
RegistryKey ctrl = k.CreateSubKey("Control");
ctrl.Close();
// Next create the CodeBase entry - needed if not string named and GACced.
RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
inprocServer32.Close();
// Finally close the main key
k.Close();
}
/// <summary>
/// Called to unregister the control
/// </summary>
/// <param name="key">Tke registry key</param>
[ComUnregisterFunction()]
public static void UnregisterClass(string key)
{
StringBuilder sb = new StringBuilder(key);
sb.Replace(@"HKEY_CLASSES_ROOT\", "");
// Open HKCR\CLSID\{guid} for write access
RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);
// Delete the 'Control' key, but don't throw an exception if it does not exist
k.DeleteSubKey("Control", false);
// Next open up InprocServer32
RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
// And delete the CodeBase key, again not throwing if missing
k.DeleteSubKey("CodeBase", false);
// Finally close the main key
k.Close();
}
#endregion
[ComVisible(false)]
public delegate void ClickEventHandler();
public new event ClickEventHandler Click = null;
void CSActiveXCtrl_Click(object sender, EventArgs e)
{
if (null != Click) Click(); // Raise the new Click event.
}
}
}
The "tabele" is an:
Code:
private System.Windows.Forms.DataGridView tabele;
The ActiveX Control is registering properly, etc.
I created a new C# Windows Form project (container for the ActiveX control).
I puted the ActiveX control without problems on the form.
The interface for the methods is working properly, but I have a problem with getting the events:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
tabelEvent.Click += new ActiveXGrid.tabelenForm.ClickEventHandler(onActivexClicked);
}
private void button1_Click(object sender, EventArgs e)
{
tabelenForm1.Add("test");
}
private void button2_Click(object sender, EventArgs e)
{
tabelenForm1.AddEmptyColumn();
}
private void button3_Click(object sender, EventArgs e)
{
tabelenForm1.AddEmptyLine();
}
public void onActivexClicked()
{
button1.Text = "OK";
}
}
}
I have declared it like this:
Code:
private ActiveXGrid.tabelenFormEvents tabelEvent;
private ActiveXGrid.tabelenForm tabelenForm1;
On the line:
Code:
tabelEvent.Click += new ActiveXGrid.tabelenForm.ClickEventHandler(onActivexClicked);
I getting an error:
"Click" ist "Methodengruppe", daher ist die Zuordnung nicht möglich.
I have an German Visual and it means tha "Click" is a "Method group", so the assignment is not possible.
Please help me, I'm working on this control a whole week.
The control is based on the article:
http://code.msdn.microsoft.com/CSAct...f43e7d#content
Thank You very much good people