Click here to Skip to main content
15,886,783 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
I am storing values in xml file. and fetching to combobox.

here I am passing combobox selected value. here adding symbol so result not came how can I solve this.

my xml code is
<?xml version="1.0" encoding="utf-8"?>
<Items>
  <Item>
    <ItemText>1/2"</ItemText>
    <ItemValue>0.5</ItemValue>
  </Item>
 </Items>


var users = from person in xmlDoc.Descendants("Items").Elements("Items")
                                where person.Element("ItemText").Value == cmbRodDiameter.SelectedItem.ToString()
                                select new
                                {
                                    ItemValue = person.Element("ItemValue").Value,
                                };

                    foreach (var items in users)
                    {
                        txtRodDValue.Text = items.ItemValue;
                    }
//here combobox value is passing 1/2"\" 
//insted of 1/2" that's y not came the result so how can I do.
Posted
Updated 5-Apr-13 3:09am
v2

Assuming you are binding your data to the combo box correctly,
then instead of using:
cmbRodDiameter.SelectedItem.ToString()

Use
cmbRodDiameter.SelectedValue.ToString()
 
Share this answer
 
Comments
U@007 5-Apr-13 9:24am    
hi pheonyx
it is also returning
"1/2\"".

I want to"1/2"" insted of "1/2\"".

So how can I achieve?
Pheonyx 5-Apr-13 9:28am    
so to clarify what you are trying to achieve:

You want to return
1/2"

and not

1/2\"

Is that correct?
What is being displayed in the combo box?
Pheonyx 5-Apr-13 9:41am    
I have had a bit of a search, and I am wondering, are you viewing the value of cmbRodDiameter.SelectedItem.ToString() in the debugger? If you are, then it is known for displaying escape characters at this stage, however when the program tries to execute it, it should ignore them. So you might be chasing a bit of a red herring.

So you can see what I mean, visit this link:

http://stackoverflow.com/questions/3551898/stringbuilder-tostring-is-adding-characters-in-the-beginning-and-ending-of
Seems spelling mistake!!

Replace
C#
xmlDoc.Descendants("Items").Elements("Items")

with
C#
xmlDoc.Descendants("Items").Elements("Item")


:)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900