0

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,

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Knvn
0

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?

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

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.