Note that there are some explanatory texts on larger screens.

plurals
  1. POListCollectionView BindingSource Refresh
    primarykey
    data
    text
    <p>I am binding ListCollectionView to BindingSource which in turn is binded to DataGridView (winforms). But Whenever new object is added to ListCollectionView BindingSource is not getting updated automatically. I need to make it NULL and re-bind again.</p> <pre><code>//Binding to Datagrid bindingProvider.DataSource = this.GetController.ProvidersView; this.dgvProviders.DataSource = bindingProvider; </code></pre> <p>After that in Add Button Click.</p> <pre><code>//Adds new object in ProvidersView Collection. this.GetController.AddEditProvider(); this.bindingProvider.DataSource = null; this.bindingProvider.DataSource = this.GetController.ProvidersView; </code></pre> <p>Can someone please let me know the easy way of refreshing the Bindingsource.</p> <p>Below is the sample code</p> <pre><code>BindingList&lt;DemoCustomer&gt; lstCust = new BindingList&lt;DemoCustomer&gt;(); BindingListCollectionView view; private void Form1_Load(object sender, EventArgs e) { lstCust.Add(DemoCustomer.CreateNewCustomer()); lstCust.Add(DemoCustomer.CreateNewCustomer()); lstCust.Add(DemoCustomer.CreateNewCustomer()); lstCust.Add(DemoCustomer.CreateNewCustomer()); view = new BindingListCollectionView(lstCust); bindingSource1.DataSource = view; dataGridView1.DataSource = bindingSource1; } private void button1_Click(object sender, EventArgs e) { this.lstCust.Add(DemoCustomer.CreateNewCustomer()); bindingSource1.EndEdit(); this.bindingSource1.ResetBindings(false); //(bindingSource1.DataSource as BindingListCollectionView).NeedsRefresh dataGridView1.Refresh(); } public class DemoCustomer : INotifyPropertyChanged { // These fields hold the values for the public properties. private Guid idValue = Guid.NewGuid(); private string customerNameValue = String.Empty; private string phoneNumberValue = String.Empty; public event PropertyChangedEventHandler PropertyChanged; // This method is called by the Set accessor of each property. // The CallerMemberName attribute that is applied to the optional propertyName // parameter causes the property name of the caller to be substituted as an argument. private void NotifyPropertyChanged(string propertyName = "") { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } // The constructor is private to enforce the factory pattern. private DemoCustomer() { customerNameValue = "Customer"; phoneNumberValue = "(312)555-0100"; } // This is the public factory method. public static DemoCustomer CreateNewCustomer() { return new DemoCustomer(); } // This property represents an ID, suitable // for use as a primary key in a database. public Guid ID { get { return this.idValue; } } public string CustomerName { get { return this.customerNameValue; } set { if (value != this.customerNameValue) { this.customerNameValue = value; NotifyPropertyChanged("CustomerName"); } } } public string PhoneNumber { get { return this.phoneNumberValue; } set { if (value != this.phoneNumberValue) { this.phoneNumberValue = value; NotifyPropertyChanged("PhoneNumber"); } } } } </code></pre> <p>Please let me know whats the issue with my code. Whenever I add any new item its not reflected in BindingSource bcoz of tht its not reflecting in DataGridView</p> <p>www.techknackblogs.com</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload