We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Grid Inherited user control

Hi,

I want to create a custom Inherited user control which derives from the syncfusion grid. I want to create a base grid with extended functionality,(like a standard menu for right clicks) that other developers can further extend. I tried creating an inherited user control in VS 2005, But could not. Am I on the right track or should I create a plain user control which wraps around the syncfusion grid object?

Any Insight would be helpful.

Thanks,
Jogesh.

3 Replies

HA haneefm Syncfusion Team June 19, 2007 09:02 PM UTC

Hi Jogesh,

You would have to derive the GridControl and set ContextMenu property to display the standard menu in a grid when you right clicked on the cell. Here is a code snippet to show this.

public class MyGridControl : GridControl
{
public delegate void objContextMenuClick(object sender ,EventArgs e);
public event objContextMenuClick ContextMenuClick;

public MyGridControl()
{
ContextMenu menu = new ContextMenu();

menu.MenuItems.Add("Copy");
menu.MenuItems.Add("Paste");
menu.MenuItems.Add("Edit");

for(int i = 0;i< menu.MenuItems.Count;i++)
menu.MenuItems[i].Click += new EventHandler(OnContextMenuClick);

this.ContextMenu = menu;
}

void OnContextMenuClick(object sender, EventArgs e)
{
if (ContextMenuClick != null)
{
ContextMenuClick(sender, e);
}
}
}

Please refer to the attached sample for implementation and let me know if this helps.
InheritedGridControl.zip

Best regards,
Haneef


JM Jogesh Menon June 20, 2007 02:13 PM UTC

Hi, Haneef,

Thank you for the prompt response. your code snipet is helpful, but what I am trying to get at is a bit different.

If I want to create a customised control based on syncfusion grid Can I

A) Create an Inherited Custom control(in VS2005)
B) Use Inheritance

From you response It seems that you have taken the inheritance approach, is approach # 1 possible ?

Thanks,
Jogesh


>Hi Jogesh,

You would have to derive the GridControl and set ContextMenu property to display the standard menu in a grid when you right clicked on the cell. Here is a code snippet to show this.

public class MyGridControl : GridControl
{
public delegate void objContextMenuClick(object sender ,EventArgs e);
public event objContextMenuClick ContextMenuClick;

public MyGridControl()
{
ContextMenu menu = new ContextMenu();

menu.MenuItems.Add("Copy");
menu.MenuItems.Add("Paste");
menu.MenuItems.Add("Edit");

for(int i = 0;i< menu.MenuItems.Count;i++)
menu.MenuItems[i].Click += new EventHandler(OnContextMenuClick);

this.ContextMenu = menu;
}

void OnContextMenuClick(object sender, EventArgs e)
{
if (ContextMenuClick != null)
{
ContextMenuClick(sender, e);
}
}
}

Please refer to the attached sample for implementation and let me know if this helps.
InheritedGridControl.zip

Best regards,
Haneef



HA haneefm Syncfusion Team June 20, 2007 10:47 PM UTC

Hi Jogesh,

Here is a minimal sample that shows this task.
InheritedUser.zip

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon