Click here to Skip to main content
11,414,234 members (73,091 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF C#4.0 combobox .NET4
Hi, I have a ComboBox in WPF with two ComboBoxItem.

I want to get a different value from each ComboBoxItem that's different from 'Content' property.

In HTML, it's like :
<select name="test" id="test">
    <option value="valueReturned1">Choice number one displayed</option>
    <option value="valueReturned2">Choice number two displayed</option>
</select>
My XAML is :
<ComboBox x:Name="cbStat">
    <ComboBoxItem Content="item one displayed"></ComboBoxItem>
    <ComboBoxItem Content="item two displayed"></ComboBoxItem>
</ComboBox>

What I have to do for put a 'value' in my ComboBoxItems that i can will get when i select an item ? (like in HTML i get the 'value' property.

I have search for a 'value' property in the ComboBoxItem but not found Frown | :(

Thanks by advance for help.
Posted 4-Oct-12 5:25am
Saesee176
Comments
Wes Aday at 4-Oct-12 10:42am
   
SelectedIndex? What kind of a "value" are you looking for?
Saesee at 4-Oct-12 10:44am
   
It's exactly what I search. The fact that we obtain the index of the item and not a custom value bothered me; but for a list defined in XAML, it will go.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Well, after a little headache... this solution looks good for me.

XAML
<combobox x:name="nameSelectionTypeStat" height="24" xmlns:x="#unknown">
          VerticalAlignment="Center" MinWidth="75">
CodeBehind :
private void nameValiderTypeStat_Click_1(object sender, RoutedEventArgs e)
{
    if (nameSelectionTypeStat.SelectedIndex == 0)
    {
        MessageBox.Show("Choice 1");
    }
    else if (nameSelectionTypeStat.SelectedIndex == 1)
    {
        MessageBox.Show("Choice 2");
    }
}
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,130
1 OriginalGriff 7,477
2 Maciej Los 3,710
3 Abhinav S 3,298
4 Peter Leow 3,084


Advertise | Privacy | Mobile
Web01 | 2.8.150427.2 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2015
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