Devexpress Binding List not refreshing GridControl

2.3k views Asked by At

I've got a windows form with a Devexpress GridControl whos Datasource is bound to FleetPreference.ManufacturerList where ManufacturerList is a BindingList<ManufacturerItem> and FleetPreference is a public property on the form.

i.e.

public class FleetPreference : FleetPreferenceBase
{
    ////
    ////
    ////
}

public class FleetPreferenceBase
{
    public BindingList<ManufacturerItem> ManufacturerList { get; set; }
}

public class Form1
{
    public FleetPreference FleetPreference { get; set; }
    public BindingList<ManufacturerItem> ManufacturerList { get; set; }

    public Form1() 
    {
        this.gridControl1.DataSource = 
             FleetPreference.ManufacturerList; // doesn't auto-update grid

        this.gridControl1.DataSource = 
             ManufacturerList; // does auto-update grid

    }
}

When adding a new item to the collection by calling FleetPreference.ManufacturerList.AddNew() this adds a new item to the original list, but the GridControl's datasource is not updated.

Upon doing some checking, when I add a new BindingList<ManufacturerItem> property to the form and bind the control to this property, the auto-update works as expected.

Is there any reason why using a nested Property would not behave as expected with automatically providing refresh events back to the GridControl?

2

There are 2 answers

0
muludag On

you can use PopulateColumns() to grid view after setting data source.

public Form1() 
{
    this.gridControl1.DataSource = 
         FleetPreference.ManufacturerList; // doesn't auto-update grid
    gridView1.PopulateColumns();

}
0
HB HONG On

Once gridcontrol bind the datasource, it seems like it doesn't update with new data. I've struggled with the similar issue.

In my case to update datasource, I tried clear the view then bind new one like below.

I hope it works for you as well.

gridControl1.BeginUpdate();

        try  
        {  
            gridView1.Columns.Clear();  
            gridControl1.DataSource = null;  
            gridControl1.DataSource = <newDataSource>;  
        }  
        finally  
        {  
            gridControl1.EndUpdate();  
        }

You can check the devexpress' official answer via the link below:

How to properly assign a new datasource to a grid at runtime?