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

Synchronize GDBG with a textbox control

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

7 Replies

AD Administrator Syncfusion Team February 26, 2005 11:45 AM

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


FL Frank Lin February 27, 2005 03:50 AM

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


AD Administrator Syncfusion Team February 27, 2005 05:24 AM

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(); }


FL Frank Lin February 28, 2005 02:10 AM

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.


FL Frank Lin February 28, 2005 02:57 AM

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.


FL Frank Lin March 2, 2005 03:53 AM

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


AD Administrator Syncfusion Team March 2, 2005 05:31 AM

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;
}

Loader.
Live Chat Icon For mobile
Up arrow icon