Windows Develop Bookmark and Share   
 index > Windows Forms General > ListControl contained values
 

ListControl contained values

I have the following method to populate the my ComboBox:
        public static void BindLookup(ListControl lst, object dataSource, string valueMember, string displayMember) {
            lst.ValueMember = valueMember;
            lst.DisplayMember = displayMember;
            lst.DataSource = dataSource;
        }

The problem is that when i add set the selected value to a value that isn't in the list it gets set to zero as the selected value.

I want to know if there is some default method to check if a value exist in the value list.
  • Changed TypeAhmad Hajou Wednesday, October 07, 2009 12:37 PM
  •  
Ahmad Hajou  Wednesday, October 07, 2009 9:50 AM
Hi Ahmad,

A simple method is to check the SelectedIndex property of the ComboBox after you set the SelectedValue. If the value is not included in the list, the SelectedIndex would be -1. You can also traverse the Items or the data source to check if the value is included in the list.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  6 hours 34 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• help with drawing on windows form and scrolling problem
• Overriding OnPaint in ToolStrip
• Mouse events for entire form
• the first C# program and the error
• How to Change the Opacity of the selected rectangular region of the picturebox?
• Can a button contain both bold and unbolded text?
• Event sequences of all Forms Controls?
• Implementing Custom Property similar to Location property.
• how Call Thread to Updata datagridview?
• Bad organization of ToolBar