Hi,
I'm using a LINQ to SQL Object in an UltraWinGrid as DataSource. Almost everything works fine but there is one problem:
If You add a new line to the LINQ Object or if You remove an existing line from the LINQ object by code (not in the grid itself), the grid doesn't react. It doesn't remove removed line and doesn't show new lines. Event setting the DataSource of the grid to nothing and back to the LINQ Object doesn't help.
If I do the same with a DataTable as DataSource it works fine.
Is there a way to solve this problem?
Thanks,
Udo
Hi Udo,
The grid binds to two types of data sources: IList and IBindingList. The IBindingList interface is much more robust and provides notifications to the BindingManager when rows are added or removed. IList does not provide these notifications. So it sounds to me like the data source you are using an IList and not an IBindingList.
I'm not a LINQ to SQL expert - perhaps there is some way to coerce the returned data into a IBindingList or BindingList<>. If so, that would be the best way to handle this.
If not, then one alternative would be to notify the grid of the changes yourself. Any time you add or a remove a row, you can call grid.Rows.Refresh(ReloadData) and the grid will refresh the display based on the current data in the data source.
Hi Mike,
I don't know how to coerce the returned data, so I've tried Your second suggestion. Unfortionately even the following code does'nt show any reaction:
Me.gridRooms.DataSource = NothingMe.gridRooms.Rows.Refresh(RefreshRow.ReloadData)Me.gridRooms.Rows.Refresh(RefreshRow.FireInitializeRow)Me.gridRooms.Rows.Refresh(RefreshRow.RefreshDisplay)Me.gridRooms.DataSource = Me._EventData.RoomsMe.gridRooms.Rows.Refresh(RefreshRow.ReloadData)Me.gridRooms.Rows.Refresh(RefreshRow.FireInitializeRow)Me.gridRooms.Rows.Refresh(RefreshRow.RefreshDisplay)
Any idea?
Thanks
thanks
This really has nothing to do with the grid. If you add a new row to the data source and the grid doesn't display that row, it's because the data source did not notify the grid that a new row was added.
The grid's DataSource should be either an IBindingList or an IList. But the IList interface is limited and doesn't have full support for all of the notifications needed to handle data binding. So you are better off using an IBindingList if you can.
The structure that is returned from a LNQtoSQL call simply isn't designed for DataBinding in Windows Forms.
The best solution I have found for using LNQtoSQL is to copy the returned data into a DataTable and bind the grid to that DataTable.
hey , i dont have such option ,
As stated above : the problem is when a pass an linq2sql table as a datasourse to a grid, after addining new row to the datasource , the grid is not effected !!!
the workaround i do is (not good but works):
private void BtnAdd_Click(object sender, System.EventArgs e) {
....
PerformAddOperation( ... );
//save display layout and restore it after the assignment to the datasource
MemoryStream stream = new MemoryStream(); GrdData.DisplayLayout.Save(stream);
WinGrid.DataSource = Linq2sqlTable.ToList(); WinGrid.Refresh(); stream.Position = 0; WinGrid.DisplayLayout.Load(stream); stream.Close(); stream.Dispose(); txtType.Clear(); }
Hello zubimenta,
Could you please attach if possible a small sample project reproducing this issue for us, I will be happy to take a look at it.
Hey, same problem with add and remove rows in the grid. Tried both of your suggestion:
the first one: there is a method
linkDataTableObj.GetNewBindingList()
which returns IBindingList
no effect
the second suggestion, the same as Udo's,
The only change is :
the layout display resets, the row is not added