Results 1 to 6 of 6

Thread: Combobox bound to an objectdatasource reverts to empty string on lost focus

  1. #1

    Thread Starter
    Addicted Member coolwater's Avatar
    Join Date
    Dec 2004
    Location
    philippines
    Posts
    215

    Combobox bound to an objectdatasource reverts to empty string on lost focus

    I have a combobox that is bound to a objectdatasource. The combobox is used as a lookup.

    My problem is everytime the combobox looses its focus it reverts to an empty string. The selection disappears (text.property will result to empty string). This is very weird.

    Any ideas?

    My Code Below:

    Code:
     Public Class frmUsers_AddEdit    
    
         Private newUser As Users 
         Private usertypeList As List(Of UserType)
    
         Private Sub LoadComboboxes()
             Try
                 usertypeList = UserTypeDB.GetUserTypeList
                 UserTypeComboBox.DataSource = usertypeList
    
             Catch ex As Exception
                 MessageBox.Show(ex.Message, ex.GetType.ToString)
             End Try
    
         End Sub
    
         Private Sub frmUsers_AddEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
             Me.LoadComboboxes()
             UsersBindingSource.Add(newUser)
    
         End Sub 
    
     end class
    
     Databindings of my UserTypeComboBox:
    
        UserTypeComboBox.DataSource = UserTypeBindingSource
        UserTypeComboBox.DisplayMember = UserType
        UserTypeComboBox.ValueMember = UserTypeID
        UserTypeComboBox.SelectedValue =  UsersBindingSource - UserTypeID
    Last edited by coolwater; Jul 24th, 2013 at 02:47 PM. Reason: add

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Combobox bound to an objectdatasource reverts to empty string on lost focus

    How is the combobox in any way relevant? You add the new user before it's even visible so what use is there for the selection anyway?

    UserTypeComboBox.SelectedValue = UsersBindingSource - UserTypeID
    Er .. no, it's UserTypeBindingSource.UserTypeID

    everytime the combobox looses its focus
    What exactly does that mean. When you click on another control in the same form, when you change forms, when you close a form?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Addicted Member coolwater's Avatar
    Join Date
    Dec 2004
    Location
    philippines
    Posts
    215

    Re: Combobox bound to an objectdatasource reverts to empty string on lost focus

    Sorry I'm new to vb.net 2010. I'm also new to subclassing. The comobobox is used as a lookup.

    My tables:
    tblUsers
    • FullName
    • UserName
    • Password
    • UserTypeID


    tblUserType
    • UserTypeID
    • UserType (Admin, Supervisor, Encoder)


    My Class Library:
    • Users.vb = table encapsulation of tblUsers
    • UserDB.vb = methods for my tblUsers


    • UserType.vb = table encapsulation of tblUserType
    • UserTypeDB.vb = methods for my tblUserType


    Data Sources:
    • UserBindingSource = Users.vb Class
    • UserTypeBindingSource = UserType.vb Class


    The frmUsers_AddEdit is the form I use to add/edit User data into the database. I'm still on the adding stage. No code yet for edit.

    Combobox Issue: Everytime I select an Item from the UserTypeCombobox (ex. "Encoder") the selection will revert back to un-selected when it loses focus. :-(
    Last edited by coolwater; Jul 24th, 2013 at 11:12 PM.

  4. #4

    Thread Starter
    Addicted Member coolwater's Avatar
    Join Date
    Dec 2004
    Location
    philippines
    Posts
    215

    Unhappy Re: Combobox bound to an objectdatasource reverts to empty string on lost focus

    Combobox still has issues. :-(
    Last edited by coolwater; Jul 25th, 2013 at 11:20 AM.

  5. #5

    Thread Starter
    Addicted Member coolwater's Avatar
    Join Date
    Dec 2004
    Location
    philippines
    Posts
    215

    Re: Combobox bound to an objectdatasource reverts to empty string on lost focus

    I answered early. The problem still exists. :-(

    The problem code is this "UserBindingSource.Add(newUser)" on form load. If I disable this code my combobox works fine.

  6. #6

    Thread Starter
    Addicted Member coolwater's Avatar
    Join Date
    Dec 2004
    Location
    philippines
    Posts
    215

    Re: Combobox bound to an objectdatasource reverts to empty string on lost focus

    I've attached the unfinished project. [ATTACH]102749
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width