CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2008
    Posts
    10

    [RESOLVED] Cannot Retreive Value Member of first Item in Combo Box

    Hi,

    I am trying to program a combo box with the data source properties set via the visual settings option instead of programatically. I have connected the Display Member of the combo box to the Name field of the Table, and the value member to the ID field.

    I have written a routine to call the selected value of the combo box by button in a message box to test to see which ID is currently selected. Everything seems to pulling ok, however the first listed item in the combo box is retrieving the second item's ID. And if I choose another item in the list and then choose the first item again, the previous item's ID value is still diaplayed when I test the selectedvalue settings.

    I was wondering what I need to in order to retrieve the first item's ID when selected, I have tried adding an empty item, however VB.NET 2005 will not let you do this when the data source properties are set. Thank you for your time. Below is the code created by the visual aid data source properties.

    Try

    Me.ChurchTableAdapter.Fill(Me.DsNewFamily1.Church)

    Catch ex As System.Exception
    System.Windows.Forms.MessageBox.Show(ex.Message)
    End Try

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Cannot Retreive Value Member of first Item in Combo Box

    The combo box index starts with 0, so you use the

    Code:
    From 0 to myCntrl.Count-1
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Sep 2008
    Posts
    10

    Re: Cannot Retreive Value Member of first Item in Combo Box

    thanks for the tip, I figured it probably had to do with combo boxes being 0 base. I used your advice with the code below, and it works if the first item is not changed to another from the combo box, however once another item from the list is selected and then the user re-selects the first item it still grabs the value member from the previous item selected.

    For i As Integer = 0 To cbChurchList.Items.Count - 1

    MessageBox.Show("This is the GUID of the Selected Church : " & " " & cbChurchList.SelectedValue.ToString(), "GUID Information")

    ' Exit Sub
    Next

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Cannot Retreive Value Member of first Item in Combo Box

    You don't have to bind the data to the combo, if you fill it yourself.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Sep 2008
    Posts
    10

    Re: Cannot Retreive SelectedValue of first Item in Combo Box

    yes I know I can just code the connection, however the examples I have seen have with the 1.1 Framework not 2.0, also I would to eventually pull the SQL commands from database itself rather than in the application pillar.

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

Featured