Results 1 to 5 of 5

Thread: After update on Combo box [Resolved]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    Resolved After update on Combo box [Resolved]

    Hi I have a combo box, which is bound to some data like so.

    VB Code:
    1. Private Sub getmaindropdata()
    2.         Try
    3.             Dim dacontcom As New SqlDataAdapter
    4.             ds.Tables("ContactsCom").Clear()
    5.             Dim spgetconcom As New SqlCommand("spgetconcom", sqlcon, Nothing)
    6.  
    7.             spgetconcom.CommandType = CommandType.StoredProcedure
    8.  
    9.             dacontcom.SelectCommand = spgetconcom
    10.  
    11.             sqlcon.Open()
    12.             dacontcom.Fill(ds, "ContactsCom")
    13.  
    14.  
    15.             sqlcon.Close()
    16.  
    17.             Me.cbocompany.DataSource = ds
    18.             Me.cbocompany.DisplayMember = "ContactsCom.CompanyName"
    19.             Me.cbocompany.ValueMember = "ContactsCom.ContactID"
    20.  
    21.         Catch ex As Exception
    22.             MsgBox(ex.ToString)
    23.  
    24.         End Try
    25.     End Sub

    Now I can't quite get my head out of a VBA mindset, but basically how do I do the below in .net

    VB Code:
    1. Private Sub cbocompany_AfterUpdate()
    2. popfields(me.cbocompany) ' me.cbocompany would give me the contactid
    3. End Sub

    As always any help would be very much appricated.
    Last edited by Oliver1; Jan 26th, 2006 at 11:34 AM. Reason: Resolved

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: After update on Combo box

    What update is this event supposed to be raised after and what is popfields supposed to be doing? If you mean after the DataSource is assigned then there is a DataSourceChanged event. If you mean after the user selects an item then there is a SelectedIndexChanged event.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    Re: After update on Combo box

    Sorry popfield is just a function that puts data in other fields depending on the item the user has selected from the combo box.

    I got this far

    VB Code:
    1. Private Sub cbocompany_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbocompany.SelectedIndexChanged
    2.         popfields(Me.BindingContext(ds, "ContactsCom.ContactID").Current())
    3.     End Sub

    But I think I should reference the value in the combo box rather than the datatable (even though i think the should be the same). My problem is the above works but it is always one record behind, eg the contactid is not the record that has just been selected, it's the previous record.

  4. #4
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: After update on Combo box

    you can use cbocompany.SelectedItem to get whatever item the user has selected. Although i havnt ever used binding so i dont know if that doesnt work with it, but in normal context hat is how to do it

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    Re: After update on Combo box

    Thanks
    popfields(cbocompany.SelectedValue)
    works and overcomes the other problem I had.

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