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.

Synchronize GDBG with a textbox control

Thread ID:

Created:

Updated:

Platform:

Replies:

25445 Feb 26,2005 09:53 AM Mar 2,2005 05:31 AM Windows Forms 7
loading
Tags: GridControl
Frank Lin
Asked On February 26, 2005 09:53 AM

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 11:45 AM

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 03:50 AM

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

Administrator [Syncfusion]
Replied On 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(); }

Frank Lin
Replied On 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.

Frank Lin
Replied On 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.

Frank Lin
Replied On 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

Administrator [Syncfusion]
Replied On 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;
}

CONFIRMATION

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.

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.

;