Results 1 to 12 of 12

Thread: [RESOLVED] selected combo item bug!

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Resolved [RESOLVED] selected combo item bug!

    Hi ,

    I am combining 2 fields in a combo box one of which is the supplierName and L/A No as alias ordersupplier which loads fine in the combo box. But when it comes to capturing the SupplierID it is always = 1.
    Below is my code in red to capture this value. Does anyone have any idea why Im getting this bug?

    Code:
    SELECT tb_LA.LANo, tb_supplier.supplierID, (RTRIM(tb_LA.LANo) + '- & - ' + tb_supplier.suppName) AS OrderSupplier FROM tb_LA 
    INNER JOIN tb_supplier ON tb_LA.supplierFID=tb_supplier.supplierID

    [
    Code:
    CODE]Dim query As String = "LASupp_Combo"
            Dim dtLASuppReport As New DataTable()
            Dim daLASuppReport As New SqlClient.SqlDataAdapter()
    
            Try
                Dim cmd As New SqlClient.SqlCommand(query, MyConn)
                cmd.CommandType = CommandType.Text
    
                daLASuppReport.SelectCommand = cmd
                daLASuppReport.Fill(dtLASuppReport)
                cboLASupp.DataSource = dtLASuppReport
                cboLASupp.DisplayMember = "OrderSupplier"
                cboLASupp.ValueMember = "LANo"
                supplierFID = CInt(CType(cboLASupp.SelectedItem, DataRowView).Item("supplierID"))
    [/CODE]
    Last edited by angelica; Sep 18th, 2008 at 01:35 PM.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: selected combo item bug!

    Can you show the code how you add items in to the combobox?

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: selected combo item bug!

    there is no direct adding of items when its databound...

    I would be more interested to know how the query looks when its just run against the database. The first thing to check is that the query is actually returning the data you want, then narrow it down from that as far as the UI binding goes.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: selected combo item bug!

    I have checked the data and it shows fine in the combo box which loads Ordersupplier that combines the LANo & supplierName.

    Its when I take an item from the datarowview (supplierID) that is giving me always the trouble having supplierID = 1


    VBDT,

    How I populate the combo boxes is giving in post #1 and even the SQL for the Stored Proc.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  5. #5
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: selected combo item bug!

    I didn’t give close look on your code. I see, you have used the data Source. Firs, I would check the type that the comboxox items hold to make sure I convert them in to right type.

    Second I would try to set the combobox.DataSource with the collection of the table rows like:
    vb Code:
    1. cboLASupp.DataSource = dtLASuppReport.Rows

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: selected combo item bug!

    VBDT,

    Ive tried your datasource and it gives an error:[CODE][/

    Complex databinding accepts a datasource either Ilist or Ilistsource.

    P.S. The supplierID is still loading 1 in the label
    Last edited by angelica; Sep 18th, 2008 at 04:38 PM.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  7. #7
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: selected combo item bug!

    Yes I have gotten that error too. But I just created a table with two columns and rows and this code works as it spouse to. I am not sure what is wrong with your code but take a look on this code and you may see what is wrong with it.

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.  
    5.         Dim dtLASuppReport As New DataTable("test")
    6.         dtLASuppReport.Columns.Add("name", GetType(String))
    7.         dtLASuppReport.Columns.Add("supplierID", GetType(Integer))
    8.  
    9.         Dim dr As DataRow = dtLASuppReport.NewRow
    10.         dr("name") = "Arman"
    11.         dr("supplierID") = 2
    12.         dtLASuppReport.Rows.Add(dr)
    13.  
    14.         dr = dtLASuppReport.NewRow
    15.         dr("name") = "Ann"
    16.         dr("supplierID") = 3
    17.         dtLASuppReport.Rows.Add(dr)
    18.  
    19.  
    20.         cboLASupp.DataSource = dtLASuppReport
    21.         cboLASupp.DisplayMember = "name"
    22.         cboLASupp.ValueMember = "supplierID"
    23.     End Sub
    24.  
    25.     Private Sub cboLASupp_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboLASupp.SelectedIndexChanged
    26.         MessageBox.Show(CInt(CType(cboLASupp.SelectedItem, DataRowView).Item("supplierID")).ToString)
    27.     End Sub
    28.  
    29. End Class

  8. #8
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: selected combo item bug!

    Of course the cboLASupp.SelectedValue is going to be 1 because that is the first record that is selected in the combobox. Have you change the selected item in the combobox?

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: selected combo item bug!

    hi VBDT,

    Just dont know. The SQL is working fine, I am somehow reloading the combo box with the data and get always the first ID. Desperate now cos I cant think why.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: selected combo item bug!

    Actually, I'm not surprised you are getting 1 for supplier ID.... you're grabbing it immediately after setting the combobox... which is going to return the first item in the combo list..... now, if you are still getting this problem in the SelectedItemChanged event (or what ever it's called this week, I have a splitting headache) ... then I'd see cause for concern... but as it is... the code is working as it should.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: selected combo item bug!

    Ok guys,

    seems to have solved it now. It was on the selecteditemchanged as you guys said. I was repopulating it on selectitemchanged and grabbing the supplierID value on page load.

    Thanks guys. and some panadols for techno pls!
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  12. #12
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: selected combo item bug!

    Quote Originally Posted by angelica
    Ok guys,

    seems to have solved it now. It was on the selecteditemchanged as you guys said. I was repopulating it on selectitemchanged and grabbing the supplierID value on page load.

    Thanks guys. and some panadols for techno pls!
    lol techno... I believe its TechGnome

    Like this guy.. but a programmer.


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