|
-
Sep 18th, 2008, 01:31 PM
#1
Thread Starter
Frenzied Member
[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! 
-
Sep 18th, 2008, 01:46 PM
#2
Re: selected combo item bug!
Can you show the code how you add items in to the combobox?
-
Sep 18th, 2008, 01:50 PM
#3
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.
-
Sep 18th, 2008, 01:58 PM
#4
Thread Starter
Frenzied Member
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! 
-
Sep 18th, 2008, 02:09 PM
#5
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:
cboLASupp.DataSource = dtLASuppReport.Rows
-
Sep 18th, 2008, 02:20 PM
#6
Thread Starter
Frenzied Member
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! 
-
Sep 18th, 2008, 02:49 PM
#7
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:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dtLASuppReport As New DataTable("test")
dtLASuppReport.Columns.Add("name", GetType(String))
dtLASuppReport.Columns.Add("supplierID", GetType(Integer))
Dim dr As DataRow = dtLASuppReport.NewRow
dr("name") = "Arman"
dr("supplierID") = 2
dtLASuppReport.Rows.Add(dr)
dr = dtLASuppReport.NewRow
dr("name") = "Ann"
dr("supplierID") = 3
dtLASuppReport.Rows.Add(dr)
cboLASupp.DataSource = dtLASuppReport
cboLASupp.DisplayMember = "name"
cboLASupp.ValueMember = "supplierID"
End Sub
Private Sub cboLASupp_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboLASupp.SelectedIndexChanged
MessageBox.Show(CInt(CType(cboLASupp.SelectedItem, DataRowView).Item("supplierID")).ToString)
End Sub
End Class
Last edited by VBDT; Sep 18th, 2008 at 02:54 PM.
-
Sep 18th, 2008, 03:04 PM
#8
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?
-
Sep 18th, 2008, 03:42 PM
#9
Thread Starter
Frenzied Member
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! 
-
Sep 18th, 2008, 04:03 PM
#10
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
-
Sep 18th, 2008, 04:41 PM
#11
Thread Starter
Frenzied Member
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! 
-
Sep 18th, 2008, 04:55 PM
#12
Re: selected combo item bug!
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|