Answer the question
In order to leave comments, you need to log in
How to display in combobox a field composed of parts?
My regards!
Help to solve the problem of displaying combobox.
I have a table in the database, described by a class.
The class has two properties - FirstName and LastName.
I need to display both items in combobox at once.
Before that, I read the Internet and showed the property of the partial class, which can help solve the problem. At first glance, yes. I made a new property, which I called FullName, I declared that it is formed as a concatenation of the LastName and FullName fields. And I realized that I lacked knowledge or some understanding of mechanics. In principle, this is the same thing (:
See how I wrote above - I use the Code First approach. Accordingly, when I declared a new field, it was added to the table. What the studio told me about, demanding to update the database.
Where did I go wrong and how can I solve the problem?
Thank you.
Answer the question
In order to leave comments, you need to log in
everything turned out to be much simpler
[NotMapped]
public string ManagerFullName { get { return ManagerLastName + " "+ ManagerFirstName; } }
If in the model you need some kind of auto-calculated field or a property of which should not be in the database, then it must be marked with the [NotMapped] attribute.
Describe your ItemTemplate for the ComboBox.
<ComboBox ItemsSource={Binding Items}>
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding FirstName}"/>
<TextBlock Text="{Binding LastName}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question