locked
datarowview.isedit always returns true? RRS feed

  • Question

  • Hi

    I have a win form with a couple of databound textboxes. it's set up as follows:

    'fill the ds

    'bind the textboxes
    txtUsername.DataBindings.Clear()
    txtUsername.DataBindings.Add(
    "Text", _TheDS.Tables("Users"), "Username")

    _TheCM = DirectCast(Me.BindingContext(_TheDS.Tables("Users")), CurrencyManager)

    --------------

    Dim
    dr As DataRowView
    dr =
    CType(_TheCM.Current, DataRowView)

    dr.IsEdit will then always return true, even if nothing's edited in the textboxes.
    dr.IsNew wokrs as expected and returns true if a call to _thecm.AddNew() has been made, and false otherwise.
    Why is this?

    /Dregg

    Wednesday, March 29, 2006 11:35 PM

Answers

  • The RowState won't do me no good since I have to do .EndCurrentEdit for that to work, and what I want to know is if the user has changed something and not yet pressed the save button - in other words I want to know if the row has been  edited/added before .EndCurrentEdit has been called.

    But I think I've found a way. The documentation on DataRowVersion says:
    After invoking BeginEdit on a DataRow, any edited value becomes the Proposed value. Until either CancelEdit or EndEdit is invoked, the row has an Original and a Proposed version.

    So given that BeginEdit is implicitly called somewhere along the way, the following will return true when a row has been edited:
    CType(_CM.Current, DataRowView).Row.HasVersion(DataRowVersion.Proposed)

    Matt - I thought this was the "Windows Forms Data Controls and Databinding" forum?


    /D

    Friday, March 31, 2006 9:20 AM

All replies

  • IsEdit does not mean that something has been changed in a row. It just means that row is in Edit mode. I would expect it to be True because your row has been bound to the textbox and basically it is an edit mode
    Thursday, March 30, 2006 1:22 AM
  • I guess ure right... And it has nothing to do with the bound textbox. I've tried it without binding the texbox, and .IsEdit still returns true. The only time .IsEdit returns false is after currencymanager.CancelCurrentEdit has been called...

    So, what I need to know is if the row has been changed or not. I know I can react to the tables ColumnChanging event, but then I would have to store and update that info myself. It would be much better to be able to get that info from the source itself.
    Do u know a better way?

    /D

     

     


     

    Thursday, March 30, 2006 1:39 PM
  • You should post this to the "Windows Forms Data Controls and Databinding" MSDN forum.  Also be sure to tell them what version of VS.NET you are using.

    Friday, March 31, 2006 5:20 AM
  • You may check the RowState property of a DataRow.

    _TheCM.EndCurrentEdit()

    Dim dr As DataRow = CType(_TheCM.Current, DataRowView).Row

    Dim rs As DataRowState = dr.RowState

    If rs = DataRowState.Added OrElse rs = DataRowState.Modified Then

         'The row is new or modified

    End If

    Friday, March 31, 2006 6:42 AM
  • The RowState won't do me no good since I have to do .EndCurrentEdit for that to work, and what I want to know is if the user has changed something and not yet pressed the save button - in other words I want to know if the row has been  edited/added before .EndCurrentEdit has been called.

    But I think I've found a way. The documentation on DataRowVersion says:
    After invoking BeginEdit on a DataRow, any edited value becomes the Proposed value. Until either CancelEdit or EndEdit is invoked, the row has an Original and a Proposed version.

    So given that BeginEdit is implicitly called somewhere along the way, the following will return true when a row has been edited:
    CType(_CM.Current, DataRowView).Row.HasVersion(DataRowVersion.Proposed)

    Matt - I thought this was the "Windows Forms Data Controls and Databinding" forum?


    /D

    Friday, March 31, 2006 9:20 AM
  • Yes, I am confused, too much coffee not enough sleep. (G)  You are in the right place.
    Friday, March 31, 2006 6:37 PM
  • after reading these posts and following the advice, I am still having an issue determining if the data has changed?

     

    VB.NET 2005  version 2.050727

     

    I have a windows form with databound textboxes and other controls

    in the form_load event I have

    tableAdapter.fill(myDataset.MyTable,lngID)

     

    in the exit button on the form I want to see if the user changed anything and prompt them if needed

     

     

    Dim cm As CurrencyManager

    Dim drv As DataRowView

     

    cm = DirectCast(BindingContext(MyDataset.Tables("Stores")), CurrencyManager)

    drv = CType(cm.Current, DataRowView)

     

    If drv.Row.HasVersion(DataRowVersion.Proposed) Then

    isDirty = True

    End If

     

    isDirty never gets set to true

     

    thanks for the help

    Friday, February 8, 2008 1:14 AM