Click here to Skip to main content
13,048,035 members (114,875 online)
Rate this:
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">
           <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>

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 18:56pm
Updated 22-Apr-11 0:33am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Perhaps you need:

string st = ((ComboBoxItem)comboBox1.SelectedItem).Content.ToString();
Rate this: bad
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();

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 26 Jul 2012
Copyright © CodeProject, 1999-2017
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