We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Binding to an ObservableCollection Supported??

I was doing this in WPF but it doesn't seem to work in windows forms.  Is this supported for the latest version of Syncfusion / GridGroupingControl?  I'm setting my data source to an empty ObservableCollection<ViewRecord> that is later filled, but the UI does not refresh while items are added...

Thanks,
-jeff

3 Replies

AS Amresh S Syncfusion Team June 16, 2016 01:03 PM UTC

Hi Jeff, 

Thank you for using Syncfusion products. 

We had analyzed your reported query in our end and couldn’t be able to reproduce the issue. Here we have provided the simple sample. In the below sample, grid can be updated once the data is added to the observable collection.  
Please refer the below attached sample for assigning the observable collection values dynamically to the grid cells. If still the issue persists, please provide us with a minimal sample or the code snippet used for assigning the dynamically added items to the grid. 

Sample: 

Regards, 
Amresh S. 



JV Jeff Voigt June 16, 2016 01:18 PM UTC

Not even close.

The example that you provided bindings the grid to an observable collection (yes).  Then when you click the add values button it created a new List<> and rebinds the data (not an observable collection).  This has nothing to do with my original question.  This is what I was trying to accomplish (that I was able to accomplish in WPF).

1) bind grid to an observable collection (could have 1 or 2 rows in it).
2) then click a button that adds a few rows to the observable collection (do not set a new datasource on the grid) and it should automatically update the grid.  That is how it works w/WPF because the grid knows to listen for changes in observable collections.

Look at your example and it does nothing of the sort.

Thanks,
-jv


PM Piruthiviraj Malaimelraj Syncfusion Team June 17, 2016 12:30 PM UTC

Hi Jeff, 
 
Thank you for update. 
 
In order to update the grid with modified ObservableCollection<>  in runtime , TableDirty property of grid and Refresh() method can be used. Please make use of the below code, 
 
Code Snippet: 
//Add the record to ObservableCollection in RunTime. 
private void button1_Click(object sender, EventArgs e) 
{ 
   for (int k = 0; k <= 5; k++) 
   { 
      Random rand = new Random(); 
      int r = rand.Next(100); 
      source.Add(new SampleSrc(r.ToString(), "Category" + r.ToString(), "SampleData" + r.ToString())); 
   } 
   this.gridGroupingControl1.Table.TableDirty = true; 
   this.gridGroupingControl1.Refresh();            
} 
 
Sample Link: 
 
Regards, 
Piruthiviraj 


Loader.
Up arrow icon