User (Old forums)MemberNovember 19, 2007 at 5:54 amPost count: 23064
Hi group, sorry for the naive questions but I’m beginning with the new 1.3 grid and linq (Orcas B2):
(1) Of course, when I set the grid items source to a LINQ query it will not be possible insert new data items. So in this case the typical scenario for a non-readonly grid could be e.g.:
– user can edit rows directly. He must then click some button to have these changes persisted to the database (datacontext submitchanges method).
– user has a button to add a new item. In this case a proper UI will be popup allowing him to enter data as required. In this case I suppose I’ll have some LINQ code which creates the new objects with their relations and then updates the database; after this I’ll have to requery and refresh the datagrid.
Anyway, this would not be an optimal scenario as users will have to explicitly click a STORE button to persist changes on existing rows, while changes will be immediately persisted when a new row is added. So, what would be in this case the suggested way? I could think of updating rows as soon as user ends his edit on an existing row, but in this case how could I trap something like an EndEdit event to persist my changes to the database (i.e. call the datacontext SubmitChanges method)?
(2) If instead I directly link a datagridviewsource to a LINQ table (an entityset) I should be able to insert new data items. E.g. (let db be the .dbml datacontext):
DataGridCollectionView dgcv = new DataGridCollectionView(db.SomeTable);
datagrid.ItemsSource = dgcv;
anyway, if I try this I can see from the debugger that dgcv.AllowNew is false and thus no insertion row appears in my datagrid: I can edit existing rows, but no place to add a new one. What’s wrong with this code piece?
Imported from legacy forums. Posted by Mathetes (had 6288 views)Xceed SupportMemberNovember 19, 2007 at 8:09 amPost count: 5658
(1) A blogger already posted something like this that could be helpful. Here is the link to the post:
Credits to mathgeekcoder!!! 😉
(2) Instead of doing:
DataGridCollectionView dgcv = new DataGridCollectionView( db.SomeTable);
I suggest doing:
DataGridCollectionView dgcv = new DataGridCollectionView( db.SomeTable.GetNewBindingList() );
Imported from legacy forums. Posted by Marcus [Xceed] (had 419 views)User (Old forums)MemberNovember 19, 2007 at 1:37 pmPost count: 23064
Thank you very much, this is very helpful. Anyway I’m still facing an issue: using the Linq-oriented datagrid as explained in the post I’ve did the following:
1) in my window constructor I instantiate a new datacontext for my database and set the LinqContext property of my LinqGrid equal to it.
2) I fill my grid with a LINQ query, set a new instance of DataGridCollectionView to its results and assign this view to the ItemsSource of my LinqGrid.
3) When I edit a row and it then loses focus, the EndEdit() override in my LinqGrid is called as expected, and the derived IsDirty property is true as expected. Thus, I proceed to submit changes but it appears that for LINQ there are NO changes pending, and nothing is stored in the backend database. Here’s the code for EndEdit:
public override void EndEdit()
if (IsDirty == true)
if ((ParentGrid != null) && (ParentGrid.LinqContext != null))
SubmitChanges is called but does nothing (and If I try logging the datacontext to an output a get an emtpy text). I must be missing something here… could anyone give a hint?
(as for the derived class code, I don’t post it to avoid unnecessary cluttering; anyway I’ve commented out the add insertion row code as this would be useless in this scenario, but there is no other relevant change in the original code from the post).
Imported from legacy forums. Posted by Mathetes (had 620 views)Xceed SupportMemberNovember 19, 2007 at 3:49 pmPost count: 5658
Try storing the IsDirty flag in a variable and calling the base version before Submit changes… Effectivelly, saving the Cells value to the data item is done during th EndEdit().
Imported from legacy forums. Posted by Marcus [Xceed] (had 966 views)User (Old forums)MemberNovember 22, 2007 at 12:19 pmPost count: 23064
Thanks, now it works! Anyway, do you have any plans to include such features in the next version? I’m really going to purchase a subscription when it will be more feature-complete (unbound columns, LINQ support, deleting rows support, etc). Keep up the good work!
Imported from legacy forums. Posted by Mathetes (had 584 views)Xceed SupportMemberNovember 22, 2007 at 2:01 pmPost count: 5658
– The row deletion feature has always been something that that is neither black or white. The reason why we intentionally did not package the feature into the component is because the feature in itself is not generic enough. By that I mean that there are so many possible different solutions/implementations/specific needs that we feel it’s up to the application really to determine what needs to be done for deletion. If you need assistance on how to build a deletion feature for your application, you can refer to the documentation (How-To section, “Deleting Selected Items” topic).
– Linq Support: We would be interested in knowing what additional support you are expecting from the DataGridControl towards Linq. We already fully support binding the DataGridControl to a Linq query ( insertion is not possible in a query, by Linq design), binding the DataGridControl to a Linq-To-SQL Context ( for the same reason as for the deletion, we do not commit data back to the database ). Knowing what are your expectations will help us find uses cases we might have omitted.
– Unbound Columns: This is something that is already on the radar ( no time frame at the moment ).
Imported from legacy forums. Posted by Marcus [Xceed] (had 421 views)User (Old forums)MemberNovember 23, 2007 at 3:37 amPost count: 23064
Hi, I agree that no specific implementation should be bound to such actions, but I’d simply like an easier way of inserting my own implementation at the right place (e.g. typically events), and the same applies to LINQ for this topic: row deletion is not so essential (it’s just a matter of handling KeyUp, but things become a little trickier when rows are editable, for we have to distinguish between PreviewKeyUp and KeyUp; here just some more documentation would be OK; maybe this is also the case of apparently trivial things like handling a double click at the row level, for which I had to refer to useful posts like http://forums.xceed.com/forums/ShowPost.aspx?PostID=9171); but something like an EndEdit event at the cell and row level (fired e.g. when the row loses focus) would allow us to place our database update code where it is required without having to create a subclass like LinqGrid (which for some things also lacks generalization, like the decision to add or not an insertion row on initialization). Many programmers come from windows Forms world where handling events like EndEdit or inserting unbound columns at will was something obvious, and in a the more powerful world of WPF we feel something is lacking here (I also noticed that things are somewhat slower in WPF datagrid compared to business applications based on windows forms datagridview, and this is a bit difficult to explain to old users, but I suppose here it depends also on the much more complex fx). Thanks again anyway, this forum is an ideal place to get answers…
Imported from legacy forums. Posted by Mathetes (had 592 views)Xceed SupportMemberNovember 23, 2007 at 7:58 amPost count: 5658
Thank you for your feedback, it is really appreciated. Be assured that we’ll consider these options for later updates.
Imported from legacy forums. Posted by Marcus [Xceed] (had 374 views)User (Old forums)MemberNovember 26, 2007 at 12:12 amPost count: 23064
Thanks for the plug Marcus!
Glad you liked my article – Sorry about the bug; I had fixed this problem a while ago (and a few others), but hadn’t updated the code.
The latest code is at:
It includes VS2008 RTM changes, peformance increase and better linq support.
Imported from legacy forums. Posted by mathgeekcoder (had 440 views)User (Old forums)MemberDecember 3, 2007 at 8:03 pmPost count: 23064
I’m trying to use the LinqDataGridControl with a custom cell validator.
The doco says to write the xaml as such
so when using the LinqDataGridControl I try
I tried using ldg:Column in the LinqDataGridControl.Columns but there is no ldg:column to use.
anyway, when I use <xcdg:Column> I can see it validating but it seems to validate on all the columns not just the specified one. Also, the call back to Base.EndEdit() in the LinqDataGridControl.cs throws an error stating that the field value is invalid. Am I supposed to catch this exception and if so, how do I retrieve the errorContent of the ValidationResult?
I’ve also tried setting the CellValidationRules in the code behind but it doesn’t make a difference.
Thanks in advance
Imported from legacy forums. Posted by Greg (had 7355 views)
- You must be logged in to reply to this topic.