Extracting value from combobox

  • Thread starter Thread starter KSor
  • Start date Start date
K

KSor

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.DVExchangeGroup}
Href: "https://193.169.16.6/Public/PSA KUNDER/(21) England/"
href: "https://193.169.16.6/Public/PSA KUNDER/(21) England/"
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
 
KSor said:
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.DVExchangeGroup}
Href: "https://193.169.16.6/Public/PSA KUNDER/(21) England/"
href: "https://193.169.16.6/Public/PSA KUNDER/(21) England/"
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
try this ( assuming you've set the DisplayMember correctly )

? comboBox_Country.Text

regards
 
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.DVExchangeGroup}
Href: "https://193.169.16.6/Public/PSA KUNDER/(21) England/"
href: "https://193.169.16.6/Public/PSA KUNDER/(21) England/"
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 ?

Cast comboBox_Country.SelectedItem to DVExchangeGroup, and use the
Name property.

Jon
 
KSor said:
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.DVExchangeGroup}
Href: "https://193.169.16.6/Public/PSA KUNDER/(21) England/"
href: "https://193.169.16.6/Public/PSA KUNDER/(21) England/"
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();
 

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