Click here to Skip to main content
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 4: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 453
1 CPallini 333
2 George Jonsson 270
3 OriginalGriff 159
4 Prasad Khandekar 135
0 OriginalGriff 4,613
1 CPallini 3,340
2 Sergey Alexandrovich Kryukov 2,879
3 George Jonsson 2,264
4 Gihan Liyanage 2,020


Advertise | Privacy | Mobile
Web02 | 2.8.140905.1 | Last Updated 4 Oct 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