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.

How to prevent bound textbox updating cell in datagrid ?

Thread ID:

Created:

Updated:

Platform:

Replies:

4511 May 16,2003 06:26 AM May 25,2003 07:26 AM Windows Forms 3
loading
Tags: FAQ
Chris
Asked On May 16, 2003 06:26 AM

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 :(

Nic
Replied On May 16, 2003 11:45 AM

Try setting TextBox.ReadOnly=True.

Chris
Replied On May 19, 2003 02:08 AM

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.

Nic
Replied On May 25, 2003 07:26 AM

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

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.

;