Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
Hello all,

I have a ComboBox with static data in silverlight. My code is as follows:
XML
<ComboBox Grid.Column="1" Grid.Row="4" Height="23" HorizontalAlignment="Left" Name="comboBox1" VerticalAlignment="Top" Width="120">
           <ComboBox.Items>
           <ComboBoxItem  Content="ASX_D"></ComboBoxItem>
           <ComboBoxItem Content="FOREX_D"></ComboBoxItem>
           <ComboBoxItem Content="FOREX_H"></ComboBoxItem>
           <ComboBoxItem Content="FUTERE_H"></ComboBoxItem>
           <ComboBoxItem Content="FUTURE_D"></ComboBoxItem>
           <ComboBoxItem Content="TRADE_H"></ComboBoxItem>
           </ComboBox.Items>
       </ComboBox>

I want to pick the selecteditem from combobox on a button click.
i am using:
string st=comboBox1.SelectedItem.ToString();

but it return System.Windows.Controls.ComboBoxItem
Please suggest to me how to pick the selected items of a combobox.

Any help is greatly appreciated.
Posted
Updated 22-Apr-11 0:33am
v3

Perhaps you need:

C#
string st = ((ComboBoxItem)comboBox1.SelectedItem).Content.ToString();
 
Share this answer
 
C#
var itemType = MyCombBox.SelectedItem.GetType();
var pi = itemType.GetProperty(MyCombBox.DisplayMemberPath);
var stringValue = pi.GetValue(MyCombBox.SelectedItem, null).ToString();
 
Share this answer
 

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