hi all,

i have designed a form which contains few controls,i want to do validation upon button click, i used errorprovider to set error if that field is empty
i used the following code

bool No_Error = true;
			if(OfficeNameComboBox.Text == "")
			{
				OffNameErrorProvider.SetError(OfficeNameComboBox,"Invalid Input");
			return	No_Error=false;
			}

i dont want to check the condition directly in the if condition
i want some thing like this

if(//get property to get the value of combo box == "")
{
//do something
}
how to achieve this!!

thanks in advance,

if(//get property to get the value of combo box == "")

Text is one of the property of ComboBox right? what is the problem you are facing?

private string Office_Name = OfficeNameComboBox.Text;
public string OfficeName
		{
			get
			{
				return Office_Name;
			}
			set
			{
				Office_Name=value;
			}
		}

private bool Is_ValidData()
		{
			bool No_Error = true;
			if(Office_Name == "")
			{
				OffNameErrorProvider.SetError(OfficeNameComboBox,"Invalid Input");
			return	No_Error=false;
			}

definitely i am doing wrong with properties, i cant figure it..i cant assign the value to the property directly
private string Office_Name = OfficeNameComboBox.Text;

i think you got my problem

Text is one of the property of ComboBox right? what is the problem you are facing?

As you mentioned in the first post you can use if(OfficeNameComboBox.Text == ""). I'm not understanding what the problem you are facing here & why you are going for creating a new property.

While coming to property, it is one of the member of a class. So you can create a property in the scope of the class. Now if you want to assign a combobox's selected text to this property you can easily assign it inside the method Is_ValidData() i.e. this.OfficeName = OfficeNameComboBox.Text; or else you can assign it in the SelectedIndexChanged event of the combobox.

This article has been dead for over six months. Start a new discussion instead.