We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback


Thread ID:





171 Apr 11,2002 07:34 PM UTC Apr 13,2002 04:15 AM UTC WinForms 1
Tags: FAQ
Asked On April 11, 2002 07:34 PM UTC

I have bind the combobox using dataset. Displaymember and value member. My value member is integer and display member is string.In runtime i want to find the value of valuemember. My valuemember have 1,24,34,56,.. i am giving 56 and the corresponding value to be selected

Clay Burch [Syncfusion]
Replied On April 13, 2002 04:15 AM UTC

This discussion assumes you have your combobox bound to a dataview. If you are using a datatable, then you can use the DefaultDataView member of the datatable as the DataSource for your combobox.
In this DataView case, the combobox's Items member is a collection of DataRowViews. We can use these DataRowViews to get the corresponding DisplayMember if we know the ValueMember, and vice versa.
The next comment is that the FindString and FindStringExact work only with the DisplayMember. So, they will not help you in looking for a ValueMember. Our solution is to add a public method to a derived combobox that does a 'FindStringExact' except that it looks at the ValueMember of the DataRowView instead of the DisplayMember. Below are some code snippets.
public class MyComboBox : ComboBox
	public int FindExactValueMember(object find)
		return FindExactValueMember(find, 0);

	public int FindExactValueMember(object find, int start)
		for (int i = start; i < this.Items.Count; ++i)
			DataRowView drv = this.Items[i] as DataRowView;
			if(drv != null &&  find.Equals(drv[this.ValueMember]))
				return i;
		return -1;

int index = comboBox1.FindExactValueMember(56); if(index > -1) comboBox1.SelectedIndex = index;


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon