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

How to prevent bound textbox updating cell in datagrid ?

Thread ID:





4511 May 16,2003 10:26 AM UTC May 25,2003 11:26 AM UTC WinForms 3
Tags: FAQ
Asked On May 16, 2003 10:26 AM UTC

I have a datagrid bound to a datatable. I also have a text box that uses DataBindings.Add to bind to a column in the datatable. When I move rows in the grid the text box tracks the change and displays text from the current grid row for the bound column. If I edit the text in the text box the change is mirrored in the datagrid. Does anyone know how I can prevent changes to the text box altering the text in the grid ? I've been trying to do this using DataRowVersion without luck, the only other way I can think of is to forget databinding and track row changes in the grid and read the value of a cell - which means writing alot more code :(

Replied On May 16, 2003 03:45 PM UTC

Try setting TextBox.ReadOnly=True.

Replied On May 19, 2003 06:08 AM UTC

Nic, unfortunately setting the text box as read only prevents users typing into it, however, the text box is used to enter a search string. When a user clicks a row in the grid the text box is auto populated (via its databinding) with data from the selected grid row. The user can 'tweak' this string before running the search. What I'm after is a way to get the grid to display the original row version, rather than the current version, or a way to undo / rollback any changes the user makes in the text box.

Replied On May 25, 2003 11:26 AM UTC

If you say that DataRowVersion doesn't work for you,try with DataBinding events Format & Parse. In code part where you bind TextBox1 to DataSource, add handler for those events: TextBox1.Databidings.Add("Text", _ dsTmp.Table1, "Column1Name") .... AddHandler TextBox1.DataBindings(0).Format, _ AddressOf FromDataTable AddHandler TextBox1.DataBindings(0).Parse, _ AddressOf ToDataTable Private Sub ToDataTable(ByVal sender As _ Object, ByVal e As ConvertEventArgs) Try e.Value = originalString Catch End Try End Sub Private Sub FromDataTable(ByVal sender As _ Object, ByVal e As ConvertEventArgs) Try originalString = CStr(e.Value) Catch End Try End Sub On Class level declare: Dim originalString as String="" Only downside is in dsTmp.GetChanges. Format event changes Column1 in current DataRow, but only those DataRows where user modified text in TextBox1. Hope this helps Nic


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