StrataFrame Forum

ChildFormDialog-Question/Problem

http://forum.strataframe.net/Topic31298.aspx

By Thomas Holste - 7/25/2012

Hi there,

I have a perentform which contains a datagridview to present and seek customer-data

and use a childformdialog to open a child-window to edit a selected record.

This is the code in my parent-form



Dim cErr As String = ""

Me.KundenBO1.Edit()

If Me.ChildKundNeu.ShowDialog(False, Me) = DialogResult.OK Then

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

cErr = "Fehler beim Speichern!"

mymsgbox(cErr, 48, cProgtitle)

Else

cErr = "Satz gespeichert!"

mymsgbox(cErr, 64, cProgtitle)

End If

Else

cErr = "Abbruch"

Me.KundenBO1.Undo(MicroFour.StrataFrame.Business.BusinessUndoType.CurrentRowOnly)

mymsgbox(cErr, 64, cProgtitle)

End If



So far, so good. The first parameter in the constructor determines, if a record ist added (True) or edited (False). Now whe I edit a record I want enable the use to undo changes in the child-form without closing and opening it again. So I put an "Undo-Button" on the form and call the Undo-Method of the childform-BO which is set up in the BO-Translations of the childformdialog as the destination BO.



KundenBO1.Undo(MicroFour.StrataFrame.Business.BusinessUndoType.CurrentRowOnly)



But this leads to the following error (Translated from german):

"Invalid conversion from type DBNull to type string"

And this is where it happens:



Public Overrides Sub SetValue(ByVal component As Object, ByVal value As Object)

Select Case Me.Field

Case KundenBOFieldNames.KUNDENNR

DirectCast(component, KundenBO).KUNDENNR = CType(value, System.Int32)

Case KundenBOFieldNames.ANREDE

DirectCast(component, KundenBO).ANREDE = CType(value, System.String)



The last Directcast is where the error happens.

I wonxder now if I am doing something wrong or if this can not be done this way.

Thanks for your help

Thomas
By Edhy Rijo - 7/25/2012

Hi Thomas,

If the data shown in the datagridview is presented to user as ReadOnly, then you could use a SF ListView which has build-in automation to show and manage a childformdialog, also you can easily color the rows based on the data conditions.
Or you can use the new StrataListView which is faster and more flexible than the SF Listview, it does not have the childform automation, but I posted a subclass version with some support for automation here: http://forum.strataframe.net/FindPost28459.aspx I even posted a VB sample project.

Also Trent posted a C# sample here: http://forum.strataframe.net/FindPost24981.aspx
By Thomas Holste - 7/25/2012

Hi Edhy,

thanks for your help. I want to use the grid because of the many abilities the datagridview offers. I tried the stratalistview which looks really nice but is to basic for me )and has it ever left the beta-status behind?). I use it in another project but in my recent project I want to use datagridviews because of the many possibilities they offer (For example, some other grids I will use need comboboxes and checkboxes instead of textboxes for presenting and editing grid-data and this seems to be far beyond the possibilities of the listview or the stratalistview. If this task is not to realise I will implement the child-windo wothout the childformdialog-control.

Best regards

Thomas
By Edhy Rijo - 7/25/2012

Hi Thomas,

I understand your reason and agree with you on that.

Now I will try to help you with the current situation which I believe the problem is the error you are getting when doing the undo.  This could end up being a large thread so if after my response you don't get the issue fixed, it would be easier if you create a quick VB sample using the SF Database with a grid and a childform so I can help you out better.

Based on your explanation, you are passing some parameters to the child form just to see if you are Adding or Editing a record, right?  If so, you don't need to do that, once the BO is translated in the child form you can check the bo.EditingState and that will tell you if you are in Adding/Editing/Idle.

Now I guess you are getting the cast error because there is no record in the BO when you are trying to do the Me.KundenBO1.Undo(MicroFour.StrataFrame.Business.BusinessUndoType.CurrentRowOnly).  Make sure the Me.KundenBO1.Count is > 0

I would assume you have used the ChildFormDialog control before, but let me explain what the BO translation does, it will simply pass the current Parent BO instance into the Child Form, so you will be working basically with the same BO in its current EditingState and when you close the child form, whatever changes you have made to that BO it will be translated back to the parent form BO instance.  Knowing that, it is important to know that you should not move the BO.CurrentRowIndex or Fill the child form BO instance again or you will get all kind of weird errors.

I love the ChildFormDialog functionality and flexibility, so I use it constantly in all my applications with and without ListViews.
By Thomas Holste - 7/26/2012

Hi Edhy,

I've traced the problem to a combobox-control. I had not set the population-propertie and after I did that, the error disappeared.

But another problem gas occured. I can now select an item from the dropdown-list but it is not displayed in the entry-part of the combo. When I then try to leacve the field I get the same dbnull-error. I am sure I missed some property-setting but haven't yet found out what.

I set the Binding-Field and business-object and the choose "Business Object" as population type. Afterwards I set up the populationdatasourcesetting by choosing the BO and its fill-method, its field to display and the three values for Display Member Format String ({0}), Dropdown Display Format ({0}) and the value member (Name of the field).

Best regards

Thomas
By Edhy Rijo - 7/26/2012

Hi Thomas,

I am glad you are finding your way out Tongue

Now for the combobox list population, it is fairly simply, the key is that the field used in the Value Member should match the one used for binding in your form's BO.  In the sample image below, I have only one field in this table and it happens to be the same used as Display Member, but most of the time it is not.
http://forum.strataframe.net/Uploads/Images/75f1634a-ff01-415d-9e32-163d.png

Also on a side note, in the Business Object Mapper (BOM) make sure you are using setting the "NULL Value Option" to "Return Alternate on Null" for each field ex: Return 0 for Integers and String.Empty or "" for Strings.  I noticed that in some 3rd party controls like DevExpress grids it helps to do this.
By Thomas Holste - 7/26/2012

Hi Edhy,

thanks again for your help. The problem was that I had to set tthe BindingFormat-Property to Text. Now everything seems to work.

Best regards

Thomas
By Edhy Rijo - 7/26/2012

Well, the BindingProperty for combobox should be set to SelectedValue no text, but if in your case is working is because something else may not be set correctly with the PopulationDataSourceSettings, see sample below:
http://forum.strataframe.net/Uploads/Images/f1ee4303-27e4-4748-b1a2-b5aa.png
By Thomas Holste - 7/26/2012

Hi Edhy,

is your property-sheet-example from a combobox set to "dropdown-list"? My combobox ist set up as "dropdown".

All my settings look like yours, except for the Bindingproperty. When I set it to selectedvalue, all records which do not have the field in the customer-record filled, show up with the first value from the lookup-table and not as intended, with an empty entry.

Best regards

Thomas
By Edhy Rijo - 7/26/2012

Thomas Holste (7/26/2012)
When I set it to selectedvalue, all records which do not have the field in the customer-record filled, show up with the first value from the lookup-table and not as intended, with an empty entry.

You need to setup the TopMostItem properties of the combo in combination with the "NULL Value Option" setup in the BOM, in the image below I setup the field in the BOM to return 0 when NULL, so using the combobox.TopMostItem I can enter a description <Enter or Select Card Code> and then the value of 0 (zero) so when I get a NULL field it will show my description.  Look it in the help file for better explanation.

http://forum.strataframe.net/Uploads/Images/40c57c65-67c9-4ba9-8631-afe9.png
By Thomas Holste - 7/27/2012

Hi Edhy,

I set BindingProperty to "selected value" and set the values for topmost-item, but when I choose anything else but the topmost-item, it is not displayed in the entry-part of the Combo.

But as long as my combobox works with the BindingProperty set to Texte I am happy that I got  working solution.

Thanks and best regards

Thomas
By Edhy Rijo - 7/27/2012

Hi Thomas,

Well this is one of those things where one can easily make a mistake selecting the wrong field or index, but if using Text is working for you and you are able to save/retrieved what you select from the combo, then leave it like that and move on.  Again without a sample project or looking at your project it is very difficult to figure out what else may be going on there.
Good luck!!!
By Thomas Holste - 8/1/2012

Hi Edhy,

thanks for your patience. I've layed this issue aside for a moment as I feel I am too stuck with it and pick it up after a while and start again with another combo.

Best regards

Thomas