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

Synchronize GDBG with a textbox control

Thread ID:





25445 Feb 26,2005 02:53 PM UTC Mar 2,2005 10:31 AM UTC WinForms 7
Tags: GridControl
Frank Lin
Asked On February 26, 2005 02:53 PM UTC

Hi All, I put a GDBG and a textbox control to show text of current cell of GDBG. Here are the codes: Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ... Dim da As SqlDataAdapter ds.Clear() da.Fill(ds, "Customers") Me.GridDataBoundGrid1.DataSource = ds.Tables("Customers") Me.TextBox1.DataBindings.Add(New Binding("text", ds, "Customers.CompanyName")) End Sub The textbox will not synchronize with GDBG. How to synchronize the textbox control with rows in the GDBG? thx

Administrator [Syncfusion]
Replied On February 26, 2005 04:45 PM UTC

Try this code to set teh data binding on the TextBox. Me.TextBox1.DataBindings.Add("Text", ds.Tables("Customers"), "CompanyName")

Frank Lin
Replied On February 27, 2005 08:50 AM UTC

Hi Clay, I tried your code. It wouldn''t work. Does it work in your example? Regards

Administrator [Syncfusion]
Replied On February 27, 2005 10:24 AM UTC

Yes. It did. Here is the sample I used. http://www.syncfusion.com/Support/user/uploads/GDBG_TextBox_da1614e2.zip The thing to check is to make sure the textbox and teh grid are using the exact same BindingContext. So, if your textbox and grid do not share the same parent, you need to use some code similar to: if(this.textBox1.BindingContext == null) { this.textBox1.BindingContext = new BindingContext(); } this.gridDataBoundGrid1.BindingContext = this.textBox1.BindingContext; to make sure that is the case. Also, if you want the grid to show changes as you type into the textbox (as opposed to seeing the change when you move the currencymanager poition in the grid), you will have to do more work. One way is to handle the TextChanged event for teh TextBox, and end the binding manager''s edit on each change. private void textBox1_TextChanged(object sender, EventArgs e) { BindingManagerBase cm = this.gridDataBoundGrid1.BindingContext[this.gridDataBoundGrid1.DataSource, this.gridDataBoundGrid1.DataMember]; cm.EndCurrentEdit(); }

Frank Lin
Replied On February 28, 2005 07:10 AM UTC

Thanks Clay. Your sample works. I notice that you used a code gererated dataset to storage random generated rows and show in the GDBG. Instead, if you use a predefined dataset dragging from VS.net control tools, it will not work. Regards.

Frank Lin
Replied On February 28, 2005 07:57 AM UTC

Hi Clay & all, I come the point. The textbox should not be bind to the underlying primary key because it''s readonly. If you do, synchronize will not work. Clay, thanks for your help.

Frank Lin
Replied On March 2, 2005 08:53 AM UTC

Hi Clay, If GDBG is set to be dockable, it''ll not synchronize with textbox controls any more. I think that because they have different bindingcontext. How to set their bindingcontext and synchronize both? thx

Administrator [Syncfusion]
Replied On March 2, 2005 10:31 AM UTC

Try handling the DockedStateChanged event and force the two controls have the same BindingContext there.
private void dockingManager1_DockStateChanged(object sender, DockStateChangeEventArgs arg)
	if(this.textBox1.BindingContext == null)
		this.textBox1.BindingContext = new BindingContext();
	this.gridDataBoundGrid1.BindingContext = this.textBox1.BindingContext;


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