I
I
Ilya2013-11-21 06:32:57
User interface
Ilya, 2013-11-21 06:32:57

How to fill in a ComboBox from the reference database and select the one that is written by default?

I'm not confident with WPF. I have a model class http://pastebin.com/ACPTvW6u , I write the received data from the database into a List of this type - List. And I display it in the DataGrid:

//get data from the database and fill in the
List plavkaList = dal.GetAllPlavka();
dataGrid1.ItemSource = plavkaList;

Everything is good in principle, BUT the catMetal field is connected with the reference table (where the fields are id, value), but now its id is simply displayed.
Question! How can I display the catMetal field in the dataGrid as a ComboBox with items filled in it from the directory database or make the DataGrid as a ComboBox Dropdown, but at the same time, the element that is recorded in the database (the catMetal field) is selected by default?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2013-11-21
@Zerpico

I figured it out myself.
Added the ArrayList categoryMetal field to the class.
fill it in when data is received, then bind it

<mys:DataGridTemplateColumn x:Name="catMetalColumns" Header="Категория металла">
                                <mys:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <ComboBox x:Name="catMetalDictColumn" ItemsSource="{Binding metalCategory}" SelectedIndex="{Binding catMetal}" />
                                    </DataTemplate>
                                </mys:DataGridTemplateColumn.CellTemplate>
                            </mys:DataGridTemplateColumn>

H
HomoLuden, 2013-11-21
@HomoLuden

You should at least implement INotifyPropertyChanged in your model. Or you can connect MVVMLight and inherit the model from ObservableObject. Otherwise, you are likely to have memory leaks. Well, the notification for binding will not work, of course.
See below for related links:
http://blogs.msdn.com/b/jgoldb/archive/2008/02/04/finding-memory-leaks-in-wpf-based-applications.aspx
http://support.microsoft. com/kb/938416/en-us
Be careful with binding to classes that do not implement INotify...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question