I am using Infragistics UltraGrid with BindingList. My bindingList gets populated by a stored procedure based on the inputs from the users. Users can select values which fires the stored procedure and repopulates the BindingList with new values.Every thing works fine except that the ultragrid doesn't get refreshed with this new set of values. Please suggest.
Hi,
How are you refreshing your BindingList? If you use the Add method, then this will notify bound control that a new row was added. If you are using some other method, and the grid is not updating itself, then you must be somehow bypassing the BindingList's notifications.
In that case, you should be able to refresh the grid by calling:
grid.Rows.Refresh(ReloadData)
Thanks but grid.Rows.Refresh(ReloadData) doesnot work either. I am reloading the data on the button click event and trying to refresh the grid.
public partial class Form1 : Form { BindingList<Emp> binding = new BindingList<Emp>(); public Form1() { InitializeComponent(); binding = LoadData(); ultraGrid1.SetDataBinding(binding, null); }
private void ultraButton1_Click(object sender, EventArgs e) { binding = LoadData1(); ultraGrid1.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.ReloadData); }
BindingList<Emp> LoadData() { BindingList<Emp> returnList = new BindingList<Emp>(); returnList.Add(new Emp { Name = "Joe" }); return returnList; }
BindingList<Emp> LoadData1() { BindingList<Emp> returnList = new BindingList<Emp>(); returnList.Add(new Emp { Name = "John" }); returnList.Add(new Emp { Name = "James" }); return returnList; } }
public class Emp { public string Name { get; set; } }
Okay...
'binding' in the code you have here is a variable. All you are doing is assigning a new BindingList to the 'binding' variable. The grid is still bound to the original data source which has not changed. In other words, you are not changing the list the grid is bound to - you are creating a new list which has no connection to the grid.
Hi Mike,
I have an ultra win grid and when i am trying to refresh grid, i can see in code that latest data is binding to grid but UI is not refreshing with latest data.
I tested with all different scenarios.
I am doing like this ;
Grid.DataSource = List <T>;
Grid.Rows.Refresh(RefreshRow.ReloadData,true);
Grid.Rows.Refresh(RefreshRow.RefreshDisplay, true);
Grid.Rows.Refresh(RefreshRow.FireInitializeRow, true);
Where <T> is a List which also contains another List for child grid.
I also changed list to Binding list , still doesn't work.
You don't need to Refresh anything if you are setting the grid's DataSource. Setting the DataSource property will implicitly refresh the display.
I can think of no reason why this would not work. Can you post a sample demonstrating the issue?
hey Mike, sorry to resurrect an old thread but i'm seeing so much out there on this topic but nothing is working.
i'm binding an ultrawingrid (13.2) to a dataset with two tables that have a relation object. All i want to do is auto refresh the data in the background preferably on background thread but if ui thread is quick that is fine.
i don't want to set the datasource everytime because that completely wipes everything out. any way i can do this effectively? does datatable implement notification? doesn't seem to happen for me.
any help is appreciated.
Al
Thanks for responding Mike. That does make sense. i ended up using a timer.
Hi Al,
DataSets and DataTables implement IBindingList. So any changes you make to the DataTable will be reflected in the grid automatically. You don't have to do anything.
If that's not working, then something is wrong. Maybe you are updating the back end and not the DataTable? Or maybe your code is updating the wrong DataTable (one that isn't bound to the grid).
I strongly advise against using threading with data bound controls. It's pretty much impossible to do this safely because when you use threads you must marhsal the data from one thread to the other and in the case of data binding, you are no in control of the communication between the UI and the background thread. The grid can access the data source at any time without your knowledge so proper marshaling is impossible and will almost certainly cause your application to crash in ways that are extremely difficult to debug.