Childform-Problem with Adding more than one record


Author
Message
Thomas Holste
Thomas Holste
StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi there,

in a main form I call a form to enter new orders. This form is connected to the

main form by a child dialog control:



Dim aParam(1) As Object

aParam(0) = "N"

aParam(1) = "B"

BestBO1.Add()

Me.ChildKlarneu.ShowDialog(aParam)

Me.ActiveControl = BestGrid



In the childform I distinguish between new positions to add and existing positions to edit. When it comes to saving, the code looks like this.



If BestBO1.Save <> MicroFour.StrataFrame.Data.SaveUndoResult.Success Then

Dim cErr As String = "Fehler beim Speichern!"

mymsgbox(cErr, 48, cProgtitle)

Else

If Me.lNeu Then

' Werte zusätzlöich holen

Me.putzekuprops()  ' Reset some form-properties

Me.Txtkunde.Text = "" ' Reset an unbound field

BestBO1.Add() ' Add a new record This BO is linked between main- and childform

BestBO1.Refresh()

Me.Refresh()

Me.ActiveControl = txtkollege ' Set focus to the first control

Else

Me.Close() ' We have choosen the edit-mode

End If

End If



If an existing record is being edited, the form closes. If a new record is saved, the childform, shall stay open and a new record shall be appended and the next position will be entered.

But this does not work. If i edit a position it works but when I enter a new position, the controls are not refreshed. When I overwrite them with new values and save this record aganin, the same happens.

When I now leave the childform and look at my grid in the main-form I can see that the first added record has been overwritten and some empty records (one for each new record which was added in my save-routine, see excerpt above).

What might be going wrong there?

Best regards

Thomas
StrataFrame Team
S
StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
It looks like the CurrentRowIndex is never being moved to the new row.  Or it is being moved to the new row, and then moved back to the original row.

There could be a couple of things causing the problem:


1.  If you have a sort on the business object, it can cause problems with Add() in that the underlying DataView will reorder the records after the new row is added.  
2.  There is a broken rule on the first record which is preventing navigation away from the row.  Try setting CheckCurrentRowBeforeNavigate = False on the business object to prevent it from aborting navigation when there is a broken rule.
Thomas Holste
Thomas Holste
StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Ben,

there is no sort on the BO. I also set the checkcurrentrowbeforenavigate to  False but it did not change anything.

I have made a little test-app based on the customer-table of the strataframesample-database. Maybe you could have a look what I might be doing wromg.

Best regards

Thomas
Attachments
Childformtest.zip (79 views, 134.00 KB)
Edhy Rijo
E
StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Thomas, Ben,
I check your sample and even tried with a DevExpress grid and got the same results, it looks like the BO is being navigated to the top somewhere in the BBS.

I added some code that will work the way you want, but that is just a simple patch.  I believe your logic of trying to add code via the ChildFormDialog all the time, may not be the best way to do this, but anyway here is my code, I simply saving the bo.CurrentRowIndex in the bo.Navigated() and testing for it after adding a new record and navigating to the new record, be aware that I renamed the company textbox to make it clear.

    Private _currentRowIndex As Integer = 0

    Private Sub Save_ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save_ToolStripButton1.Click
        If Me.CustomersBO1.Save() = MicroFour.StrataFrame.Data.SaveUndoResult.Success Then
            Me.CustomersBO1.Add()
            If Me._currentRowIndex <> Me.CustomersBO1.CurrentRowIndex AndAlso Me._currentRowIndex > 0 Then
                Me.CustomersBO1.Navigate(MicroFour.StrataFrame.Business.BusinessNavigationDirection.Absolute, Me._currentRowIndex)
            End If
            Me.txtCompany.Focus()
        End If
    End Sub

    Private Sub CustomersBO1_Navigated(e As MicroFour.StrataFrame.Business.NavigatedEventArgs) Handles CustomersBO1.Navigated
        If Me.CustomersBO1.EditingState = MicroFour.StrataFrame.Business.BusinessEditingState.Idle Then
            Me._currentRowIndex = Me.CustomersBO1.CurrentRowIndex
        End If
    End Sub


Edhy Rijo

Thomas Holste
Thomas Holste
StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)StrataFrame User (294 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Edhy,

thanks a lot for your help, I will try it right now. After testing a whole lot more I think the childformdialog-control is just not capable of doing things like I wanted it to do. In the help-file the examples are limited to adding a record and then returning to the parentform.

But there are some alternatives I am testing right now like passing the mainform-bo to the childform in the constructor of the childform and then use it. Or by using a separate bo and updating when returning to the mainform.

Best regards

Thomas
StrataFrame Team
S
StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Thomas, 

Yes, in scenarios that are more complex than just opening the child form once to add a new record and return, it is generally better to call your child dialog explicitly and pass the reference to the business object in the constructor.  There is a fair amount of "smoke and mirrors" that goes on with the ChildFormDialog to shuffle the business objects between the forms.  There's a lot of pushing and popping of references going on and you will have more control if you implement it yourself.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search