none
Set a default value to a combobox with ef RRS feed

  • Question

  • Hi,

    I new to vb2010 and .net 4.0. I have developed 6 years in VB6.

    I have made a Entity Data Model to a Class Library. Two tabels in the model are customer and language with a relationship 1 to many.

    I made a xaml window with two collectionviewsources : customersource, languagelookup. The windows is populate good. Know I want to set default values to the windows. I made a new class in the model for the customer with the following contructor:

    Public Class tabCustomer
        Dim db As New FredFactEntities
    
        Public Sub New()
            'Set the default values
            Me.fldCstVisible = True     'Is working well
    
            'The combobox in filled in but not with dutch but with the last I juist
            'Dim cstLanguage As New tabLanguage("NL")       
            'Me.tabLanguage = cstLanguage       'If I check the values of tabLanguage they are correct
            ''The combobox in filled in but not with dutch but with the last I juist
            ''Me.tabLanguage = New tabLanguage
            ''Me.tabLanguage.fldLngCode = "NL"
            ''Me.tabLanguage.fldLngName = "Nedelands"
    
            'The customer data is not loaded any more and there is not default value loaded
            For Each lngDummy In db.LanguageFindByCode("NL")
                tabLanguage = CType(lngDummy, tabLanguage)
            Next
        End Sub
    End Class
    

    I tried several solutions but non works.

    Can you help me with this? I searching already 10 houres for it.

    Thanks a lot

    Friday, April 12, 2013 7:14 AM

Answers

  • On 4/12/2013 3:14 AM, dwphilippe wrote:

    Hi,

    I new to vb2010 and .net 4.0. I have developed 6 years in VB6.

    I have made a Entity Data Model to a Class Library. Two tabels in the model are customer and language with a relationship 1 to many.
    I made a xaml window with two collectionviewsources : customersource, languagelookup. The windows is populate good. Know I want to set default values to the windows. I made a new class in the model for the customer with the following contructor:

    Public Class tabCustomer
             Dim db As New FredFactEntities
    
             Public Sub New()
                     'Set the default values
                     Me.fldCstVisible = True         'Is working well
    
                     'The combobox in filled in but not with dutch but with the last I juist
                     'Dim cstLanguage As New tabLanguage("NL")
                     'Me.tabLanguage = cstLanguage             'If I check the values of tabLanguage they are correct
                     ''The combobox in filled in but not with dutch but with the last I juist
                     ''Me.tabLanguage = New tabLanguage
                     ''Me.tabLanguage.fldLngCode = "NL"
                     ''Me.tabLanguage.fldLngName = "Nedelands"
    
                     'The customer data is not loaded any more and there is not default value loaded
                     For Each lngDummy In db.LanguageFindByCode("NL")
                             tabLanguage = CType(lngDummy, tabLanguage)
                     Next
             End Sub
    End Class
    

    I tried several solutions but non works.
    Can you help me with this? I searching already 10 houres for it.
    Thanks a lot

    dim lngcode = db.LanguageFindByCode.Where(Function(item) item.fldlngcode = "NL").SingleOrDefault The above is assuming that there is an object in LanguageFindByCode with a property callled "fldlngcode" or whatever the property name you are using in the object. If Not IsNothing(lngcode) then '' the object was found and you can get data out of the object dim code = lngcode.fldlngcode Else '' the object was not found end if OR dim lngcode = db.LanguageFindByCode.Where(Function(item) item.fldlngcode = "NL").FirstOrDefault If Not IsNothing(lngcode) then '' the object was found and you can get data out of the object dim code = lngcode.fldlngcode Else '' the object was not found end if <http://www.advancesharp.com/questions/150/linq-singleordefault-vs-firstordefault> You have .First and you have .Single - look them up.

    Friday, April 12, 2013 7:41 PM