I have a ComboBox, which already has some assigned items, loaded by means of an enumeration (Enum):
public enum TERCERO_TIPOID : byte {
[Display(Name = "Nit")]NIT,
[Display(Name = "Cedula Cuidadania")]CC,
[Display(Name = "Cedula Extranjeria")]CE,
[Display(Name = "Pasaporte")]PASAPORTE,
[Display(Name = "Tarjeta Extranjeria")]TAR_EXT,
[Display(Name = "Doc. Id Extranjeria")]DOCID_EXT,
[Display(Name = "Tarjeta Identidad")]TAR_IDEN,
[Display(Name = "Nuip")]NUIP,
[Display(Name = "Codigo")]COD,
[Display(Name = "Otros")]OTRO = 9 }
In the comboBox it shows me the DataAnotation of the name, so all right, but in the database when I consult the People table there is a field called "TipoDoc" that by requirements is a bit field, for when loading TipoDoc brings me a number from 1 to 9 no more, but I need to load a user the comboBox I load the type of document you have.
If I do it, for example with a Combo_Tipo.SelectedIndex = 3;
the comboBox will select the third one in the "Passport" list, but I need the ComboBox to be selected with the value, instead of using the SelectedIndex use the SelectedValue. That to put it for example Combo_Tipo.SelectedValue = "Nit";
I leave selected the type of document NIT.
But in doing so he does not let me do it. How do I do it? What am I doing wrong?
The SelectedIndex captures me and assigns me the value in the combo.
The SelectedValue only captures the data of the Combo but does not assign it to me when I need it.
Combo:
<ComboBox Header="Tipo Documento:" Width="150" HorizontalAlignment="Center" VerticalAlignment="Top" x:Name="Combo_TipoDoc" SelectedItem="{Binding Tipoid, Mode=TwoWay}" />
and this is the object in the field in the VM:
public TERCERO_TIPOID Tipoid { get => tipoid; set { tipoid = value; RaisePropertyChanged(); } }
private TERCERO_TIPOID tipoid;
and so I charge it in the codeBehind of the XAML window osea TerceroPage.xaml.cs
this.Combo_TipoDoc.ItemsSource = Enum.GetValues(typeof(TERCERO_TIPOID)).Cast<TERCERO_TIPOID>();