For this problem, I'll need you to actually download the attached ZIP file. It's VB.NET source code, so yeah, go ahead and look at it before you run it. It works with the Northwind database, so you shouldn't have any problems there.
It consists of a form1.vb, and a class1.vb.
First, the problem:
Load up the form. It'll load everything, listbox, combo boxes, textboxes, everything.
Now, you'll have the first record loaded up: Product "Chai" (btw, that's the Persian word for Tea)
Without editing anything, press the update button, and watch the Supplier's combobox change value! The Category combobox does not, even though I'm using the same technique to udpate them.
Also, you'll notice that the form's title has changed to the .SelectedIndex of the combobox.
Press Update again.
it's just going to keep changing. It goes in a very weird loop.
If I use a rougher technique to do the update it works fine. (which you will find commented out underneath the actual line being used)
Can someone take a look? It's absolutely baffling.
Last edited by mendhak; Jun 24th, 2004 at 06:34 AM.
Hmmm...bad code.
That's basing it on the fact that the 1st index in the DB is 1 and that NON are missing. What if the index goes 1,2,3,7,14,23,24,25...your selectedindex won't work.
What on earth is the purpose of your class1 (ListItemNumeric)???!!!
Originally posted by Wokawidget Hmmm...bad code.
That's basing it on the fact that the 1st index in the DB is 1 and that NON are missing. What if the index goes 1,2,3,7,14,23,24,25...your selectedindex won't work.
What on earth is the purpose of your class1 (ListItemNumeric)???!!!
Wpopooof
That is not the issue, what I've shown here is a very crude workaround. THeoretically, I should not be having to resort to such a technique, and be using the commented line instead. But it just doesn't work.
ListItemNumeric is a class I wrote that can hold a Value and an ID, so that I can populate my listbox with a bunch of ListItemNumeric objects that have a displayed value, and an underlying ID, and that takes care of the situation you mentioned, where the IDs are not in an order.
Originally posted by Wokawidget Yes and yes. I am still failing to see why you are using a class...???
Woof
I'll try to explain:
As you're seeing, the listbox on the left has a lot of values in it. Now everytime you click on another item in the listbox, the values in the textboxes and comboboxes change. For this, the database needs to be requeried each time.
And most logically, to query the database for the values corresponding to any particular item in the listbox, we need a Primary Key, correct?
I needed a place to store the primary key. So, since the listbox actually accepts objects, I declared a class that would hold a .VALUE property (which is what you are seeing, "Chai") and a .ID property (which you don't see), used when querying.
Try to think of another way to do this same thing, you'll find that this is an ideal way to do it.
In my opinion at least. I'm new to VB.NET, so it's possible that there is a better way. So far, I don't see a better way.
Originally posted by Wokawidget You muppet!
You are saving the CORRECT ID's to the DB...but when you load them you are treating the ID as the LISTINDEX! Hahahaha
VB Code:
Private Sub FindItem(ByVal cboName As ComboBox, ByVal strID As String)
Anyways, your problem was nothing to do with .NET
You would get EXACTLY the same thing happening if you did that in VB6. Stop smoking joints...Hahahaha
Item is a property of Items...I don't see what the problem is here.
Item is just the default property of Items, thus Items(1) = Items.Item(1)...Woof
If you have Items.Item(1) and you delete the . and then press . then the .NET IDE does NOT take you to the Item property in the drop down auto thingy...VB6 does...stupid .NET
Yes, that is correct. Same difference. I got the problem here:
VB Code:
If lItem.ID = lngID Then
lngID was never declared, so I don't know how it worked for you. I changed it to strID, and modified the line you mentioned out of personal preference.
Private Sub FindItem(ByVal cboName As ComboBox, ByVal lngID As Long)
lngID IS declared.
You must have done something wrong...
U had strID in your code.
I changed this to lngID since it is a long and there is no point in passing it as a string only to convert it back to a long.