combobox selecteditem to string

  • Thread starter Thread starter gordon
  • Start date Start date
G

gordon

Hi

I have a combo box that my application uses to select an item for a
regression function.

I would like to convert the selected item to a string value and use this
value later in my code.

I have used
private string charVal;

public string CharVal

{

set

{charVal = tbCharVal.SelectedItem.ToString();}

get

{return charVal;}

}



But i get an error 'C:\eg_1\eg_3\Reg1.cs(38): Cannot implicitly convert type
'object' to 'string'' . Could someone show me how to convert the
selectedItem to a string value?

thanks
 
Hi Gordon,
from looking at the code below I suspect you are doing something like this:

myObject.CharVal = tbCharVal.SelectedItem;

which is trying to implicitly assign an object to the string property
CharVal. Inside the set method of your property you want to assign the
implicit value instance to your variable i.e.

public string CharVal
{
get
{
return charVal;
}
set
{
charVal = value;
}
}

then you have to set a string value in your calling code i.e.
myObject.CharVal = tbCharVal.SelectedItem.ToString();

Hope that helps
Mark R Dawson
http://www.markdawson.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top