Beginner problem using combobox value

I have a basic silverlight project that I am doing in an attempt to learn the program.  I have a decent amount of experience programming office projects within the MS office suite using VBA, but have not done a lot of standalone programming.  My end goal is to create a rectangle that is animated based on the parameters given from a series of controls --

I am starting using a combobox to attempt to change the duration of the animation that I have defined on the rectangle.   I am having a problem simply getting the value from the combobox however.  

The combobox is defined as:

 <ComboBox   Height="27" Name="cboDuration" Width="114"  >
            <ComboBoxItem Content="1"  />
            <ComboBoxItem Content="2" IsSelected="True"  />
            <ComboBoxItem Content="3" />
            <ComboBoxItem Content="4" />
</ComboBox>

Currently I am simply trying to get the value that is selected out of the combobox and display it with a message box.  I have tried the following:  

MessageBox.Show(cboDuration.SelectedValue.ToString()) -- returns System.Windows.Controls.ComboBoxItem

MessageBox.Show(cboDuration.SelectedItem.ToString()) -- returns System.Windows.Controls.ComboBoxItem

MessageBox.Show(cboDuration.SelectedIndex.ToString()) -- returns the correctly selected Index -- not really useful though since I still cannot grab the value

MessageBox.Show(cboDuration.SelectedItem) (or SelectedValue) without the .ToString() results in a conversion error.  
VoodooFrogAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

urban_smurfCommented:
Hi VoodoFrog,
Change your messagebox code to the following:

MessageBox.Show(cboDuration.Items.Item(cboDuration.SelectedIndex).ToString)

Hope that helps!
0
VoodooFrogAuthor Commented:
I am still just getting the System.Windows.Controls.ComboBoxItem  value showing up when I change it to what you suggest.  It seems that the SelectedItem and the Items.Item() refer to the same point.  

Could there be something wrong with the way I set the combobox up in the XAML?  it seemed simple enough, and with the selectedIndex it even seems to work...  
0
urban_smurfCommented:
That is quite strange, i tried again and this code works correctly:

Dim cbi As ComboBoxItem
cbi = ComboBox1.SelectedItem
MessageBox.Show(cbi.Content.ToString())
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CuteBugCommented:
Use this

MessageBox.Show(((ComboBoxItem)cboDuration.Items[cboDuration.SelectedIndex]).Content.ToString());
0
VoodooFrogAuthor Commented:
thank you urban -- it was the .Content that I was missing.  I appreciate your help.  

CB -- tried yours, I think the formatting doesn't work in VB, which I am using for this project.  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.