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

User controls in Grid

Thread ID:





5746 Jul 16,2003 02:34 PM UTC Jul 18,2003 02:30 PM UTC WinForms 7
Tags: GridControl
Stephen Rose
Asked On July 16, 2003 02:34 PM UTC

Is there a simple way to put a custom user control eg with a text box and a couple of buttons into a grid cell. If so, how? Cheers Steve

Administrator [Syncfusion]
Replied On July 16, 2003 03:55 PM UTC

Try the steps below. They will step you through using the new "Control" celltype in 1.6.1. They simply put a TextBox in a cell, not very useful. But you can try the same thing with any control. So, you could use a buttonedit or a a panel holding several controls or ???. This technique is useful if you only have a few such controls in your grid as you have to instantiate a new control for each cell that uses the control. If you have many such cells, then you would want to derive the class and enable control sharing. 1- Create a new windows application 2- Drop a GridControl on the form. 3- Double click an empty area on the form and place the following code in the Form Load event. TextBox box = new TextBox(); box.Multiline = true; box.Text = "Some random text here..."; box.BorderStyle = BorderStyle.None; gridControl1.RowHeights[2] = 30; gridControl1.ColWidths[2] = 200; gridControl1[2,2].CellType = "Control"; gridControl1[2,2].Control = box; this.Controls.Add(box);

Stephen Rose
Replied On July 17, 2003 01:27 PM UTC

Thanks, that works really well.... The only problem now is that it takes one click to select the cell and one to the do anything on the control in the cell, eg tick a check box. Am I doing something wrong or alternativly is there a way I could pass on the click to the control... Many thanks Steve

Administrator [Syncfusion]
Replied On July 17, 2003 09:52 PM UTC

The Generic cell control does try to click the cell for you. You will notice that with the TextBox sample code, the textbox activates on the first click. But if the control is a panel or usercontrol, then the generic cell click does is not sufficient to activate the proper control for you. In such a case, you can handle your control's Enter event, and in the event set the focus to the child control you want to get it. Suppose your control is panel that has a checkbox on it. Here is code that would 'click' the checkbox on the first click.
private void panel1_Enter(object sender, System.EventArgs e)
	if(Control.MouseButtons == MouseButtons.Left)
		Point loc = Control.MousePosition;
		Point p = this.panel1.PointToClient(loc);
			this.checkBox1.Checked = !this.checkBox1.Checked ;

Stephen Rose
Replied On July 18, 2003 09:57 AM UTC

I am actually creating a normal user control, which Inherits System.Windows.Forms.UserControl creating a new control and adding it to the grid. The code you gave doesnt actually work as the button is always none and never anything else. As is the parent(grid) mouse button. Even putting this on the mouse-move event of the user control doenst pick anything up. Any ideas Cheers Steve

Administrator [Syncfusion]
Replied On July 18, 2003 11:40 AM UTC

Is the enter event being hit? Are you parenting the UserContol to the form as is done in the code snippet with the textbox?

Stephen Rose
Replied On July 18, 2003 02:02 PM UTC

I am adding the control to the grid as below: GridControl1(1,1).CellType = "Control" GridControl1(1,1).Control = New GridCheckNumber The event does get hit but the mouse button is not recorded as being down. I have tried this on various other mouse move events of the control, but none have the mouse button recorded as being down. Steve

Administrator [Syncfusion]
Replied On July 18, 2003 02:30 PM UTC

You might try adding your control to the form's Controls collection. dim ctl as new GridCheckNumber() GridControl1(1,1).CellType = "Control" GridControl1(1,1).Control = ctl Me.Controls.Add(ctl); to see if that makes a difference.


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon