How to update data in ComboBox after changing ListBox/db?

MeisonSan 40 Reputation points
2023-04-10T20:40:18.9566667+00:00
when you click on the button (change delete add) a window opens with a TextBox in which I specify name, age
so after I click ok, the data is correctly displayed in LisBox, which I can’t say about comboBox

3

3(3)

2

2(2)

when you click Open_Click, a window opens with LisBox, which also displays name, age data and here it is possible to change delete add (new entry)1(1)

on the main window there is a comboBox that displays name, age data,1

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
790 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 43,046 Reputation points Microsoft Vendor
    2023-04-11T09:05:51.23+00:00

    Hi @Максимилиан Янулевич, Welcome to Q&A. You could try the following code to get what you wanted.

    One easy way:

    //after modifying the data
    DataContext=null;
    DataContext =db.Users.Local.ToObservableCollection(); 
    

    For real-time modification of Name and Age, change the binding method to:

    <TextBlock Text="{Binding Name,Mode=TwoWay}" FontSize="16"/>
    <TextBlock Text="{Binding Age, Mode=TwoWay}" FontSize="13"/>
    

    You may need to refer to this document:Binding declarations overview (WPF .NET)

    Another way you should implement INotifyPropertyChanged interface for your binding source object.

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful