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.
Unfortunately, activation email could not send to your email. Please try again.

Usercontrol in cell

Thread ID:

Created:

Updated:

Platform:

Replies:

14607 Jun 1,2004 02:26 AM Jun 2,2004 08:32 AM Windows Forms 7
loading
Tags: GridControl
Mathias
Asked On June 1, 2004 02:26 AM

Hello! Is it even possible to insert your own custom usercontrol into a gridcell? I''ve looked at the samples and I''ve also tried implementing my own model and rendering classes, but without result. I''m using the MonthCalendarAdv control and what I would like to do basically is to "hi-jack" the cells, so I can maintain a calendar structure and functionality, but with my own control instead of just the date in each cell.

Mathias
Replied On June 1, 2004 03:29 AM

OK, let me rephrase my question: I''ve managed to display a custom control in a gridcell of a normal gridcontrol (using celltype = "control" and Control property in the PrepareViewStyleInfo eventhandler). But if I do the same subclassing the MonthCalendarAdv, the datevalue is still displayed, and the control is not shown. How can I get past this?

Administrator [Syncfusion]
Replied On June 1, 2004 04:13 AM

In a GridControl, you can just set these properties in FormLoad. You do not necessarily have to set them dynamically in PrepareViewStyleInfo. But, if you want to set them dynmically, you probably should try QueryCellInfo instead of PrepareViewStyleInfo. I was able to put a derived MonthCalenderAdv in a cell using this code and have it show up. Here is the sample. this.gridControl1[2,2].CellType = "Control"; this.gridControl1[2,2].Control = this.monthCalendarAdv1; But if you want to use more than 1 or 2 of these, you should derive your own cell control. Take a look at this sample, 2.0.5.1\Grid\Samples\CellTypes\CalendarCells. It uses a MonthCalendar, but I think you should be able to do something similar with a derived class.

Mathias
Replied On June 1, 2004 05:50 AM

Thanks for your response, However, my problem is the other way around: I have an inherited MonthCalendarAdv where I want to display a control in each one of the "date"-cells (I''ve overridden InitializeGrid to gain access to the internal grid of MonthCalendarAdv), but I can''t even do this in the "non-dynamic" way as you did. I''ve tried the same in a normal grid (like in your sample-code), and then it worked just fine, but for some reason I can''t seem to get past the date being displayed in each cell when subclassing a MonthCalendarAdv.

Administrator [Syncfusion]
Replied On June 1, 2004 06:33 AM

So you want to puts special control in a cell within the MonthCalendarAdv control itself? Try using QueryCellInfo instead of PrepareViewStyleInfo. This code seems to work in the sample posted above.
public class MyMonthCalendarAdv : MonthCalendarAdv
{
	protected override void InitializeGrid(ref Syncfusion.Windows.Forms.Grid.GridControlBase grid)
	{
		base.InitializeGrid(ref grid);
		grid.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(grid_QueryCellInfo);
	}

	Button b = new Button();
	private void grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
	{
		if(e.ColIndex == 3 && e.RowIndex == 2)
		{
			e.Style.CellType = "Control";
			e.Style.Control = b;
		}
	}
}

Mathias
Replied On June 1, 2004 08:59 AM

Thanks again for your response, This is exactly what I need, but it only works in design-view and not in run-time (your code, that is). I can put any control in there, and it shows up in VS design mode of the form, but not in runtime...

Administrator [Syncfusion]
Replied On June 2, 2004 02:59 AM

The reason this is working the way it is (OK at design time, but not OK at runtime) is because the MonthCalendarAdv is relying on grid events to provide the data (calendar dates) to the control. For you to add a special cell control to the calendar, you also are trying to rely on some of the same events. With events, whoever gets the events last, actually controls what happens. And with eventing architecture, there is no guarantee the order in which event handlers are hit. In the design-time case, your handler is taking precedence. In the runtime case, the default handler in the base class is getting control. Normally, the way around this is to derive the classes involved, override the virtual OnXXXXX methods that fire the events, and control things that way. BUT, in this case, the InitializeGrid method does not allow for this to be done easily. If you try to do this now, you would end up copying a lot of the class code up into your derived class. I will forward this problem onto the tools team that so maybe they can modify the InitializeGrid method to allow for you to easily slip in your own grid class, and have it used by the MonthCalenderAdv. This would allow you to easily derive the GridControl to handle the problem regarding who has control over the virtual OnQueryCellInfo method which is the crux of the problem here.

Mathias
Replied On June 2, 2004 08:32 AM

Thanks alot for your help, Clay I think the problems lies in the fact that the MonthCalendarAdv control is using a GridControlBase instead of a regular GridControl. This more basic gridcontrol doesn''t support "Object" celltypes, and therefore defaults to a static celltype. Like you said, it would be great if you could set the grid yourself.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;