简体   繁体   中英

Binding Refresh on a dataGrid WinForms

Hey guys I have problem with binding and refreshing binding.

I am using Entity Framework with WindowsForms...

I am retrieving orders from Shipping Queue and binding them to the grid.

if I open another form and and move Order X to different Queue, my grid does not reflect that...

So for example, the Main form has a two grids and a button

Grid 1 = Orders in Shipping Queue 
Grid 2 = Orders in New Order Queue
Button 1 = Manage Orders

If I click my "Manage Orders" button and open up Order X that is in the Shipping Queue and move it to the New Orders Queue, I want the change to be reflected in the grids.

I tried different stuff and the cheapest and best solution I came up with was to call update on the grids every few minutes but I feel that there must be a better way...

Any thoughts?

Ensure that the values you're binding to are calling OnPropertyChanged() properly.

public class Class1 : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    private int myValue;
    public int MyValue
    {
        get { return myValue; }
        set 
        {
            if (myValue != value)
            {
                myValue = value;
                OnPropertyChanged("MyValue");
            }
        }
    }

    protected virtual void OnPropertyChanged(string property)
    {
        var notify = PropertyChanged;
        if (notify != null)
            notify(this, new PropertyChangedEventArgs(property));
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM