Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a multi columns combobox. After combo population, I try to set the default values, but I get an error message

This is my codes

XML
public ObservableCollection<Model_Sedi> Sedi { get; set; }
    private Model_Sedi _Sedi_Search;
    public Model_Sedi Sedi_Search {
	get { return _Sedi_Search; }
	set {
		_Sedi_Search = value;
		OnPropertyChanged("Sedi_Search");
	    }
        }

<ComboBox x:Name="Cmb_Sede"                    
            ItemsSource="{Binding Sedi, Mode=TwoWay}"
                          SelectedValuePath="Value"
                          SelectedItem="{Binding Sedi_Search, Mode=TwoWay}" 
                          
                          VerticalAlignment="Top" Width="189">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding IdSede, UpdateSourceTrigger=PropertyChanged}"></TextBlock>
                        <TextBlock Text="{Binding Sede, UpdateSourceTrigger=PropertyChanged}" Padding="10,0,0,0"></TextBlock>
                    </StackPanel>
                </DataTemplate>
            </ComboBox.ItemTemplate>
            <ComboBox.Effect>
                <DropShadowEffect Color="#FF0A0A0A" Opacity="0.6"/>
            </ComboBox.Effect>
        </ComboBox>



Now, how can I set the default values ? (like this doesn't work)

C#
Sedi_Search.Sede = "ABC"
Sedi_Search.IdSede = 111
Posted
Updated 17-Jan-15 0:12am
v2
Comments
LLLLGGGG 17-Jan-15 13:13pm    
What error message do you get?

LG

1 solution

In the view model, you need to new your Sedi_Search with your default values and add it to the collection.


C#
Sedi_Search= new Model_Sedi{Sede="ABC",IdSede=111};
Sedi.Add(Sedi_Search);
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900