Results 1 to 3 of 3

Thread: FindByText & FindByValue

  1. #1

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

    FindByText & FindByValue

    I know that using asp.net I can use "FindByText" and "FindByValue" to get find an item in a dropdown but is there no similar way to do this in a windows application.

    Basically I have a string value and wish the dropdown to display the correct item to match the string.

    Parksie

  2. #2
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: FindByText & FindByValue

    Assuming you're using VB.Net you can use "IndexOf" to set the index of a given value by doing;

    MyComboxBox.SelectedIndex = MyComboBox.Items.IndexOf("MyValueString")

    I think you can also do;

    MyComboBox.SelectedItem = "MyValueString"
    Last edited by Bulldog; Jan 8th, 2007 at 08:02 AM.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: FindByText & FindByValue

    The ComboBox doesn't have text and corresponding values unless it is bound to a data source. It has FindString and FindStringExact methods that llow you to find the index of an item by the text displayed for that item but there is no method to find an item by value. You can set the SelectedValue property directly, otherwise you'd have to find your desired item using methods of the data source.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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