|
-
Oct 14th, 2002, 08:55 AM
#1
Thread Starter
Fanatic Member
Search with a combo
I have a form shwong a list of stock 1 record at a time.
I have set up a combobox which displays a list of "itemID"'s which is the Primary key for the table.
Using the above approach I can successfully search the form.
The problem I have is that the ID numbers are meaningless to the user so I need to put "itemDescription" in the combo with "itemID" in the itemvalue property.
I cannot get this to work.
Does anyone have any suggestions or examples on how to do this???
-
Oct 14th, 2002, 10:13 AM
#2
From your previous post I believe you said you are using a dataset as your datasource, correct? If so then just run a .Select method on it to find a match. It will return an array od datarows that match which are still connected to the dataset.
-
Oct 14th, 2002, 10:36 AM
#3
Thread Starter
Fanatic Member
Is there any chance you could expand a little bit.
I have tried everything I can think of to get the valuemember and find the appropriate record and my head is going to explode.
Man, I have been using this .NET for a few weeks now and it is blowing me away. This is nothing like VBA.......which is probably a good thing but I find that things I could do in VBA in 15 minutes now take me all day.
Still........patience is a virtue
-
Oct 14th, 2002, 10:44 AM
#4
This will give you an array of datarows from the dataset that match the selected item description:
VB Code:
Dim dr() As DataRow = ds.Tables(0).Select(String.Concat("ItemDescription='", ComboBox1.SelectedText, "'"))
-
Oct 14th, 2002, 11:01 AM
#5
Thread Starter
Fanatic Member
I have tried that but I am not sure how I get the fields into my textfields on the form:
e.g. Me.txtDescription.Text = objROw.Item("itemDescription")
is how I originally did it.
I am of course making the assumption that only 1 record will be present in the table/
-
Oct 14th, 2002, 11:08 AM
#6
And whats the problem? Although the Select method will return an array of datarows even for one value (I believe).
VB Code:
Dim dr() As DataRow = ds.Tables(0).Select(String.Concat("itemDescription='", ComboBox1.SelectedText, "'"))
If Not dr is nothing then
Me.txtDescription.Text = dr(0).Item("itemDescription")
End If
-
Oct 14th, 2002, 11:20 AM
#7
Thread Starter
Fanatic Member
I tried the following:
If Not objROw Is Nothing Then
MsgBox(objROw(0).Item("itemDescription"))
Me.txtDescription.Text = objROw(0).Item("itemDescription") End If
But got this:
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in StockSystemNet.exe
Additional information: Index was outside the bounds of the array.
You can give up on me if you like.
Thanks for eveything so far. I feel like a bloody idiot.
-
Oct 14th, 2002, 11:41 AM
#8
My Bad you must have to check the index of the array instead of for nothing:
VB Code:
Dim dr() As DataRow = ds.Tables(0).Select(String.Concat("itemDescription='", ComboBox1.SelectedText, "'"))
If ubound(dr)=>0 then
Me.txtDescription.Text = dr(0).Item("itemDescription")
End If
-
Oct 15th, 2002, 06:36 AM
#9
Thread Starter
Fanatic Member
RESOLVED
Thanks for all your help Edneeis.
I eventually got it working a treat.
Dim dr() As DataRow = ds.Tables(0).Select(String.Concat("itemDescription='", ComboBox1.SelectedText, "'"))
didnt work for some reason but when I changed the Selecttext to Selectitem it did. Strange!!!!
Thanks again.
Now to try and package my application with Crystal.
Happy, Happy, Joy, Joy.
-
Aug 21st, 2005, 02:12 AM
#10
Frenzied Member
Re: Search with a combo
yes, 3 years later, this solved my problem too! thanks
Wen Gang, Programmer
VB6, QB, HTML, ASP, VBScript, Visual C++, Java
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
|