error when BO is empty


Author
Message
Felix M Avendano
Felix M Avendano
StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)
Group: Forum Members
Posts: 48, Visits: 1.5K
I have a form with 2 comboboxes, one datagrid, 3 BO's and one BBS. The Bo's are related between them in a father, child, grandchild relationship. The BBS is attached to the datagrid. The datagrid receives the data of the grandchild.

I have the code that follows in the form:

Public Class frmTrabajoseinsumos


    Private Sub ComboBox2_ListPopulating(ByVal e As MicroFour.StrataFrame.UI.ListPopulatingEventArgs) Handles ComboBox2.ListPopulating
        If Me.BoEmpresa1.Count > 0 Then
            e.Parameters(0).Value = CInt(ComboBox1.SelectedValue)
        Else
            e.Parameters(0).Value = 0
        End If

    End Sub

    Private Sub ComboBox1_ParentFormLoading() Handles ComboBox1.ParentFormLoading
        Me.BoEmpresa1.FillAll()
    End Sub


    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If (CInt(ComboBox1.SelectedValue)) > 0 Then
            BoTipotrabajoinsumo1.FillByCustomPK(CInt(ComboBox1.SelectedValue))
            ComboBox2.Requery()

        End If
        If Me.BoTrabajoinsumo1.Count > 0 Then
            BoTrabajoinsumo1.FillByCustomPK(CInt(ComboBox1.SelectedValue), CInt(ComboBox2.SelectedValue))
        End If
    End Sub


    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        'If Me.BoTrabajoinsumo1.Count > 0 Then
        BoTrabajoinsumo1.FillByCustomPK(CInt(ComboBox1.SelectedValue), CInt(ComboBox2.SelectedValue))
        DataGridView1.Refresh()


    End Sub

End Class

The problem cames in the last ComboBox2_SelectedIndexChanged. When the query of the FillByCustomPK cames with no data and the BO is empty I get the following error:

The CurrentRow for table '[dbo].[Trabajoinsumo]' could not be evaluated because the CurrentRowIndex is out of range.  Business object record count: 0.  CurrentRowIndex: -1.

The error is launched in a part of the generated code:

''' <summary>
    ''' Tipoactividad
    ''' </summary>
    <Browsable(False), _
     BusinessFieldDisplayInEditor(), _
     Description("Tipoactividad"), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    Public Property [Tipoactividad]() As System.Int32
        Get
            Return CType(Me.CurrentRow.Item("Tipoactividad"), System.Int32)
        End Get
        Set(ByVal value As System.Int32)
            Me.CurrentRow.Item("Tipoactividad") = value
        End Set
    End Property

Ive being trying to do my best but I cant find a solution in order to avoid the error, unless I change the generated code, and that's awfol.

Any Sugestion wil be well received.

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Felix,



The rule is that whenever you will be accesing the BO property, you must check for the BO.Count like you are doing for the other combos.



Also, instead of using the combo.SelectedValue, use the binded property of the combo:



e.Parameters(0).Value = BO.PropertyName)



Edhy Rijo

Felix M Avendano
Felix M Avendano
StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)
Group: Forum Members
Posts: 48, Visits: 1.5K
Edhy Rijo (09/02/2009)
Felix,

The rule is that whenever you will be accesing the BO property, you must check for the BO.Count like you are doing for the other combos.

OK to this, I'll be more carefull.w00t


Also, instead of using the combo.SelectedValue, use the binded property of the combo:

e.Parameters(0).Value = BO.PropertyName)

This is the one I'm more interested on. Thanks for the suggestion.Smile

Regards

Felix M Avendano
Felix M Avendano
StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)
Group: Forum Members
Posts: 48, Visits: 1.5K
Ive change everything as suggested and now I have 2 Comboboxes bounded to a cuple od BO's and a datagridview bounded to a BBS and this bbs to a BO. Everything works fine intil I try to exit the form. When I go out of it thru the close form icon I get this error. Any Clue, because I cant debug it because it doesn't pass thru my code.

KeyNotFoundException
  La clave proporcionada no se encontró en el diccionario. (the key provided is not found in the diccionary)

Source     : mscorlib

Stack Trace:
   en System.ThrowHelper.ThrowKeyNotFoundException()
   en System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   en MicroFour.StrataFrame.Business.BusinessLayer.get__CurrentDataTable(Boolean IsSharedTable)
   en MicroFour.StrataFrame.Business.BusinessLayer.get_Count()
   en MicroFour.StrataFrame.Business.BusinessBindingSource.get_IBindingListView_Count()
   en System.Windows.Forms.CurrencyManager.get_Count()
   en System.Windows.Forms.DataGridViewCell.GetValue(Int32 rowIndex)
   en System.Windows.Forms.DataGridViewCell.GetFormattedValue(Int32 rowIndex, DataGridViewCellStyle& cellStyle, DataGridViewDataErrorContexts context)
   en System.Windows.Forms.DataGridViewTextBoxCell.GetPreferredSize(Graphics graphics, DataGridViewCellStyle cellStyle, Int32 rowIndex, Size constraintSize)
   en System.Windows.Forms.DataGridViewCell.GetPreferredWidth(Int32 rowIndex, Int32 height)
   en System.Windows.Forms.DataGridViewCell.OnCellDataAreaMouseEnterInternal(Int32 rowIndex)
   en System.Windows.Forms.DataGridViewCell.OnMouseMoveInternal(DataGridViewCellMouseEventArgs e)
   en System.Windows.Forms.DataGridView.OnCellMouseMove(DataGridViewCellMouseEventArgs e)
   en System.Windows.Forms.DataGridView.UpdateMouseEnteredCell(HitTestInfo hti, MouseEventArgs e)
   en System.Windows.Forms.DataGridView.OnMouseMove(MouseEventArgs e)
   en System.Windows.Forms.Control.WmMouseMove(Message& m)
   en System.Windows.Forms.Control.WndProc(Message& m)
   en System.Windows.Forms.DataGridView.WndProc(Message& m)
   en System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
   en System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   en System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
That problem was fixed in the latest version 1.7.0.2, download it from your account and you should be good.

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Yup, please download the most recent build and see if your problem persists. Thanks.
Felix M Avendano
Felix M Avendano
StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)
Group: Forum Members
Posts: 48, Visits: 1.5K
It did work fine, but I still have a problem.

I tried to simplyfied it the best I could in one form because I have this in 3 forms and I cannot solve it. Let's see.

I have a Datagridview bounded via a BBS to a first BO. The Data... has a combobox inthere bounded to a second BO via a second BBS. I populate evreything as well and when I try to add a record using the datagrid directly, or via a Button with the add function is the same, I have a very ugly message, but I cannot debug it, or I don't know how to do it.

Ill attach you the message window.

Attachments
error.jpg (135 views, 55.00 KB)
Felix M Avendano
Felix M Avendano
StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)
Group: Forum Members
Posts: 48, Visits: 1.5K
I've finally found where the error is:

at windowsaplication1.BOempresa  (is a BO of course Smile)

       Public Overrides Function GetValue(ByVal component As Object) As Object
            Select Case Me.Field
                Case BOEmpresaFieldNames.Descripcion
                    Return DirectCast(component, BOEmpresa).Descripcion
                Case BOEmpresaFieldNames.CUIT
                    Return DirectCast(component, BOEmpresa).CUIT
                Case BOEmpresaFieldNames.Dirección
                    Return DirectCast(component, BOEmpresa).Dirección
                Case BOEmpresaFieldNames.Ubicacion
                    Return DirectCast(component, BOEmpresa).Ubicacion
                Case BOEmpresaFieldNames.Empresa  (after passing 4 times here)
                    Return DirectCast(component, BOEmpresa).Empresa
                Case Else
                    Throw New BusinessLayerException("Field not supported.")
            End Select
        End Function

Felix M Avendano
Felix M Avendano
StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)StrataFrame Novice (62 reputation)
Group: Forum Members
Posts: 48, Visits: 1.5K
Now I have something good!!!

If I put Empresa as parent key works fine. The problem is, what about having two or more foreing keys. I cannot put more than one parent.

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
So what you are saying is that you need to register more than one foreign key for the BO, correct? You can use the RegisterForeignKey method on the BO and pass over the child BO and the key information. This must be done in code, but will server the exact same purpose as the standard ParentRelationship property available through the designer.
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