This is a migrated thread and some comments may be shown as answers.

Adding new rows to database via RIA services

6 Answers 189 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 18 Mar 2010, 10:44 PM
Hi:

I'm building an SL4 version of an existing time & billing application.  For time charge entry, I need to display a RadGridView showing the most recent 20 time charges entered for an employee.  The user should be able to edit these entries, including start date, start time, end time, customer (from dropdown), project (from dropdown), and charge description.  There are good examples for this sort of functionality and it looks relatively easy to do.

However, when the user wants to add a new charge (via clicking a button, or perhaps hitting the enter key), I need to add a new row at the bottom and allow entry of the necessary columns by tabbing from one column to the next.  When the user is done, he/she will hit the enter key, and the row will be added to the database.

Are there any good examples of this sort of functionality?

Thanks,

Terry

6 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 22 Mar 2010, 04:16 PM
Hello Terry,

I'm attaching a sample project which demonstrates how to add new rows via RadGridView to a database using RIA services. Unfortunately with the current version of the RadGridView new item cannot be added at the bottom, instead RadGridView uses a special insert UI at the top just under header row.

P.S. The attached example uses SL 3 Telerik assemblies (should work with SL4 assemblies as well), Northwind and SQL Server 2008 express edition. For another version of SQL server you have to edit a connection string entry within "web.config" file.

All the best,
Nedyalko Nikolov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Terry
Top achievements
Rank 1
answered on 22 Mar 2010, 11:57 PM
But when you hit the Insert key on the keyboard (with focus on the grid) in your demos, that adds arow at the bottom.

So whatever happens there, I cannot trigger that programatically?
0
Vlad
Telerik team
answered on 23 Mar 2010, 07:41 AM
Hi Terry,

You can call RadGridView BeginInsert() method to add new row in the grid programmatically.

Best wishes,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Terry
Top achievements
Rank 1
answered on 24 Mar 2010, 12:14 AM
Hi Vlad:

I am unable to get this example to run.  In VS2008, I get a message that projects 3 - 6 have moved.  In VS2010 RC, I just get the message that the last 4 projects couldn't be converted.  And of course the RIA namespaces are changed.  This is understandable as things are changing pretty fast on the Microsoft SL front, But I'll need to find another way to solve my problem.

I can bind to an EntitySet<> based upon a table (It does have a primary key) and an ObservableCollection<> based on a class I build, but in neither case does an Insert keystroke or a BeginInsert() call generate a new row in the grid.  I've set CanUserInsertRows = "True".  So can you give me a very simple example where this works?  It doesn't need to be RIA, but if it is, I can only work with the .NET 4 RC version.

What types of collections can I edit/insert with a RadGridView?

Thanks,

Terry
0
Terry
Top achievements
Rank 1
answered on 24 Mar 2010, 12:32 AM
BTW, I've also made sure IsReadonly= "False".  I've tried .AsQueryable(), ToList(), and pretty much everything I can think of.  I do have CellEditTemplates defined for the columns and they seem to work Ok with existing rows.  (Except the TimePicker displays blank rather than the actual time when you go into edit mode, but that's another post I've made)
0
Nedyalko Nikolov
Telerik team
answered on 26 Mar 2010, 06:15 PM
Hi Terry,

Generally you will be able to add new items automatically into RadGridView if:

1. RadGridView is bound to a collection that implements IList interface, because of the AddNew() method.
2. Your business object has a parameter less constructor - AddNew uses this constructor to create an appropriate item.

If this is not your case you have to handle RadGridView.AddingNewDataItem event, which is called when RadGridView.BeginInsert() is called (or "Insert" key is pressed), and provide new instance to the e.NewObject property.

I'm attaching a SL 4 version of the example from my previous post that demonstrates how to implement this with RIA services, since this is the most elegant way to deal with databases on a server.

Let me know how this works on your end.

Sincerely yours,
Nedyalko Nikolov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Terry
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Terry
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or