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

Usercontrol in cell

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.

7 Replies

MA Mathias June 1, 2004 07:29 AM UTC

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?

AD Administrator Syncfusion Team June 1, 2004 08:13 AM UTC

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,\Grid\Samples\CellTypes\CalendarCells. It uses a MonthCalendar, but I think you should be able to do something similar with a derived class.

MA Mathias June 1, 2004 09:50 AM UTC

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.

AD Administrator Syncfusion Team June 1, 2004 10:33 AM UTC

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;

MA Mathias June 1, 2004 12:59 PM UTC

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...

AD Administrator Syncfusion Team June 2, 2004 06:59 AM UTC

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.

MA Mathias June 2, 2004 12:32 PM UTC

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.

Live Chat Icon For mobile
Up arrow icon