473,387 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

combobox selecteditem to string

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


Nov 17 '05 #1
1 15310
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


"gordon" wrote:
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


Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
1
by: tupolev | last post by:
Hello, I want allow the user to edit the items but the only thing I found is to delete and insert items. Is there a way how you can do that and in with event? I tried...
8
by: mongphong28 | last post by:
Hi, I'm populating a ComboBox with objects which contain two properties - IntegerValue and StringValue. I display StringValue in the ComboBox form and can retrieve IntegerValue from the...
10
by: news.microsoft.com | last post by:
I am new to this so bear with me. I have a set of combo boxes. Lets call them ComboBox1 and ComboBox2. ComboBox1 items are pulled from a table. When a user selects a certain item I want to...
1
by: JP | last post by:
I have C# ASP.NET VS 2005 combo box set to perform an auto post back when the user changes the index protected void dropSSNEdit_SelectedIndexChanged(object sender, EventArgs e) { txtSSN.Text...
0
by: muchinger | last post by:
All, I create 2 combo boxes on a page: an editable one and a non-editable one. Both of them have the same string items which are too long to entirely fit into the combo box. E. g. the size of...
11
Frinavale
by: Frinavale | last post by:
This question is going to sound a little crazy but.........How do you set the selected item in a ComboBox? I am populating a ComboBox with a bunch of instances of a custom private class: For...
1
by: kimic | last post by:
Hello, i am using WPF combobox in my application. 1) I create and add a combobox to a visual container (usualy Grid) by runtime or it is defined in the XAML page 2) I assign combobox source to the...
1
JnrJnr
by: JnrJnr | last post by:
Hi, I have a combobox that is databound. It displays all the cities. Its DisplayMember is "City" and its ValueMember is "CityID" At runtime I am trying to change the SelectedItem....
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.