Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hello all,
 
I have a ComboBox with static data in silverlight. My code is as follows:
<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 21-Apr-11 19:56pm
Edited 22-Apr-11 1:33am
Slacker00775.8K
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Perhaps you need:
 
string st = ((ComboBoxItem)comboBox1.SelectedItem).Content.ToString();
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

var itemType = MyCombBox.SelectedItem.GetType();
var pi = itemType.GetProperty(MyCombBox.DisplayMemberPath);
var stringValue = pi.GetValue(MyCombBox.SelectedItem, null).ToString();
  Permalink  

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



Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 26 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100