"KSor" wrote:
Quote:
I have a combobox I want to extract the "selected value" BUT
>
When I ask in the Immidiate window I get this - an object-valuie I think :
>
? comboBox_Country.SelectedItem
>
{EstiMate.Components.Exchange.DataLayer.DVExchange Group}
Href: "https://193.169.16.6/Public/PSA%20KUNDER/(21)%20England/"
href: "https://193.169.16.6/Public/PSA%20KUNDER/(21)%20England/"
Name: "(21) England"
name: "(21) England"
>
>
And what I want to extract is the "(21) England" in the Name/name of the
object - but how ?
>
Best regards
KSor, Denmark
>
>
>
Hi KSor,
SelectedItem holds an object reference so immediate will do its best to
display useful information from the object. To extract just the Name
information you can cast the object to the proper type and directly read the
Name property:
MyObject myObj = comboBox_Country.SelectedItem as MyObject;
string s = myObj.Name;
Specify displaymember/valuemember on the ComboBox I would imagine you would
display the name and use the url as value
comboBox_Country.DisplayMember = "Name";
comboBox_Country.ValueMember = "Href";
string s = comboBox_Country.Text;
string u = comboBox_Country.SelectedValue.ToString();
Displaymember and Valuemember must be valid properties.
You can override ToString on your object and return the Name property.
public class MyObj
{
public string Name{ get{ return name; } }
public override ToString(){ return Name; }
}
....
string s = comboBox_Country.SelectedItem.ToString();
--
Happy Coding!
Morten Wennevik [C# MVP]