Results 1 to 10 of 10

Thread: Search with a combo

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    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???

    Parksie

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  3. #3

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    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

    Parksie

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    This will give you an array of datarows from the dataset that match the selected item description:
    VB Code:
    1. Dim dr() As DataRow = ds.Tables(0).Select(String.Concat("ItemDescription='", ComboBox1.SelectedText, "'"))

  5. #5

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    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/

    Parksie

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    And whats the problem? Although the Select method will return an array of datarows even for one value (I believe).

    VB Code:
    1. Dim dr() As DataRow = ds.Tables(0).Select(String.Concat("itemDescription='", ComboBox1.SelectedText, "'"))
    2. If Not dr is nothing then
    3. Me.txtDescription.Text = dr(0).Item("itemDescription")
    4. End If

  7. #7

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    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.

    Parksie

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    My Bad you must have to check the index of the array instead of for nothing:
    VB Code:
    1. Dim dr() As DataRow = ds.Tables(0).Select(String.Concat("itemDescription='", ComboBox1.SelectedText, "'"))
    2. If ubound(dr)=>0 then
    3. Me.txtDescription.Text = dr(0).Item("itemDescription")
    4. End If

  9. #9

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    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.


    Parksie

  10. #10
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    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
  •  



Click Here to Expand Forum to Full Width