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

Databound user controls in grid cells

Thread ID:





59487 Apr 13,2007 07:26 PM UTC Apr 19,2007 11:12 PM UTC Windows Forms 5
Tags: GridControl
Jeff Lancaster
Asked On April 13, 2007 07:26 PM UTC

I have a user control which contains a textbox which may be bound to a property of a class. I am able to dynamically set the data binding properties at runtime and add these to a form as needed - so far so good.

Now what I am trying to do is dynamically add these controls into cells within a Syncfusion grid. For example:

Dim CellControl as new BoundFieldControl(ObjToBind, BindingDef)
grid(1, 1).CellType = "Control"
grid(1,1).Control = CellControl

Now what is happening is that the controls within the cells do properly get populated with the data to which they are bound, however when I type into the bound textbox, the changes are not being propogated back to the datasource.

What might I be missing?

Jeff Lancaster
Replied On April 17, 2007 11:01 PM UTC

Bump... Any thoughts on this?

Administrator [Syncfusion]
Replied On April 18, 2007 12:34 AM UTC

Are you trying to use this usercontrol in more than one cell? If so, are you creating a new CellControl for every grid cell where you want to use it as in this code?

Dim CellControl as new BoundFieldControl(ObjToBind, BindingDef)
grid(1, 1).CellType = "Control"
grid(1,1).Control = CellControl

CellControl = new BoundFieldControl(ObjToBind, BindingDef)
grid(1, 2).CellType = "Control"
grid(1,2).Control = CellControl

Using a "Control" CellType requires each cell to have its own instance of the control.

If this is not the problem, if you upload a sample project showing what you are trying to do, we can try to tweak it to get it working.

Jeff Lancaster
Replied On April 18, 2007 04:49 PM UTC

Yes, I am putting a new instance of the control in each cell.

I have attached a very simple sample to demonstrate the issue. In this example I have created an object called "Customer" with a property "Name". I have also created a user control called "BoundFieldControl", which contains only a label and a textbox. When instantiated, the textbox is bound to the "Name" property of a passed object. Now when the form is loaded, two instances of BieldFieldControl and one instance of Customer are created. Customer name is populated with the text "Bill Smith". You will see that the first instance of BoundFieldControl is placed in a panel on the form, the second on inserted in to Cell (1,1) of a syncfusion grid. Since the BoundFieldControls are both bound to Customer.Name, "Bill Smith" is displayed in both places on the form. Also notice the "Display Name" button - when pressed it displays the current Customer.Name which is initially "Bill Smith".

Now, change the name in the textbox of the top BoundFieldControl to "Bill Jones" and hit the tab key - notice that it also changes to "Bill Jones" in the control in the grid. Furthermore if you press the "Display Name" Button, you can see that Customer.Name has properly been updated to "Bill Jones".

Next, change the textbox in the control in the Grid to "Bill Johnson", then move the focus. Notice that the TextBox in the upper control still reads "Bill Jones". Click the button to see the current Customer.Name - it still reads "Bill Jones". It seems that something about the control being inside the grid is preventing it from correctly propogating changes back to the underlying datasource.

Thank you for helping with this,


Administrator [Syncfusion]
Replied On April 18, 2007 07:10 PM UTC

Thanks for the sample.

There are a couple of things going on here. The first is that the control is unparented to begin with. When you click on it in the grid the first time, the control actually is reparented to the grid and it is this reparenting that is breaking the binding. This problem can be avoided by just initially adding the control to the grid.Controls collection so its parent does not change.

Another problem is that the grid does not know when it needs to refresh itself. This can be handled through a cople of events on the usercontrol.

Here is your sample back with these changes.


Jeff Lancaster
Replied On April 19, 2007 11:12 PM UTC

Thanks for the help, Clay...that did the trick.


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.

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