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

User controls in Grid

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

7 Replies

AD Administrator Syncfusion Team 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);

SR Stephen Rose 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

AD Administrator Syncfusion Team 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 ;

SR Stephen Rose 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

AD Administrator Syncfusion Team 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?

SR Stephen Rose 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

AD Administrator Syncfusion Team 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.

Live Chat Icon For mobile
Up arrow icon