Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WPF/EF - Refreshing a combo after adding new item

$
0
0

I have code that adds a new item to a combobox if a user enters data that is not part of the current list.  The problem is that the new item gets added but doesn't stick to the control and displays the first item in the list instead.

If "Bbbbbbb" is attempted and answered Yes:

This is the result.  Bbbbbb doesn't stick and Aaaaaa is displayed instead, which is the first item in the list.

Bbbbbb has been put into the list.

This is how I check the combo and refresh it:

        If Not String.IsNullOrEmpty(cboCaseManager.Text) Then
            Try
                Dim query = From x In _context.tlkpCaseManagers
                    Where x.CaseManager = cboCaseManager.Text
                    Select x
                Dim c As IEnumerable(Of tlkpCaseManager) = query.ToList()

                If c.Count = 0 Then
                    Dim msg As String = "Do you wish to add it to the list for future reference?"
                    Dim caption As String = "'" & cboCaseManager.Text & "'" & " is not in the Case Manager list"
                    Dim response = MessageBox.Show(msg, caption, MessageBoxButton.YesNo, MessageBoxImage.Question)
                    If response = MessageBoxResult.Yes Then
                        Dim newCaseManager As New tlkpCaseManager() With { _
                                .CaseManager = cboCaseManager.Text
                            }

                        _context.tlkpCaseManagers.Add(newCaseManager)
                        _context.SaveChanges()
                        cboCaseManager.ItemsSource = _context.tlkpCaseManagers.ToList()
                    End If
                End If


Thanks.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>