I'm using a GridView control in a basic winform application (.net 3.5) . I'm using a sql server database table datasource. I set the gridview to AllowAddNewRow and AllowEditRow. Very easily setup the app to view the data. I'm able to insert and update records in the grid. But those insert/updates are not committed to the database.
I would appreciate any direction to help me learn how to simply add/update/delete records via the gridview.
Thanks!
19 Answers, 1 is accepted
Thank you for your question.
In general, you may find more resources in our documentation which can be accessed online. In particular, RadGridView does not have internal data structures but uses its datasource object. Therefore, whatever is displayed in the RadGridView in bound mode is the content of your datasource. The reverse is also true. If you change the data in your data source object the UI is notified about the change and refreshes the cells content. In your case, this is probably a typed DataSet automatically generated by Visual Studio for your data base. If so, the data should be persisted. Please check the documentation for your DataSource in msdn. Perhaps you need to call an Update on your data base adaptor if you are using the disconnected data base model. Depending n your requirements you should choose the most suitable event on which you should call Update. For example:
- RadGridView.CellEndEdit - this executes after each cell is edited
- BindingSource.ListChanged
- Save button click, etc
If you want to edit your data programmatically outside the grid (e.g. adding row using a button on your form), my general tip is to use your DataSet, BindingList, etc API when you handle your purely data base operations and RadGridView API when your data source API cannot be used. Most of the time you will not need the second approach at all, because the RadGridView will handle presentation automatically.
Do not hesitate to write me back if you have more questions. Sending us a sample project or a code snippet can be very useful when answering your questions and reproducing the issues that you have encountered.
Regards,
Nick
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Thank you for the guidance! I appreciate it.
Thanks in advance.
In general, you may find more resources in our documentation which can be accessed online. In particular, RadGridView does not have internal data structures but uses its datasource object. Therefore, whatever is displayed in the RadGridView in bound mode is the content of your datasource. The reverse is also true. If you change the data in your data source object the UI is notified about the change and refreshes the cells content. In your case, this is probably a typed DataSet automatically generated by Visual Studio for your data base. If so, the data should be persisted. Please check the documentation for your DataSource in msdn. Perhaps you need to call an Update on your data base adaptor if you are using the disconnected data base model. Depending n your requirements you should choose the most suitable event on which you should call Update. For example:
- RadGridView.CellEndEdit - this executes after each cell is edited
- BindingSource.ListChanged
- Save button click, etc
If you want to edit your data programmatically outside the grid (e.g. adding row using a button on your form), my general tip is to use your DataSet, BindingList, etc API when you handle your purely data base operations and RadGridView API when your data source API cannot be used. Most of the time you will not need the second approach at all, because the RadGridView will handle presentation automatically.
Do not hesitate to write me back if you have more questions. Sending us a sample project or a code snippet can be very useful when answering your questions and reproducing the issues that you have encountered.
Regards,
Mike
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I can edit, insert into the radgrid but without change in my datasource
please help!!!!!!!
I suggest that you read the responses of my colleagues Nick and Mike. The answer to your question is most probably given there.
If you can't find the answer for your particular scenario, we will need detailed description of your databinding approach. It will be best if you open a new support ticket and send us a sample project. This will allow us to help you further.
Greetings,
Nikolay
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I answered that question here.
http://social.msdn.microsoft.com/Forums/en/sqlce/thread/a4bae5d5-f8bb-44a9-921c-ea817193ae01
In the RadGridView_RowsChanged event add the code
this.TableAdapter.Update(this.Dataset.Table) which takes care of the update.
Use e.Action to trap Insert/Delete/Update and code accordingly.
i am new to telerik controls and windows application.
can any body tell me how to update the database after updateing the hierarchical grid (parent and child row).
which event should i use to get the cell values for both parent and child row and update the database.
please suggest.
thanks in advance.
Did you check the answer posted above your question, or the other pointers that Mike provided?
Those points should help you do what you want,
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga
Thanks for reply.
i didnt get the above post.
which event should i use to update the database.
i am ushig heararchy grid.
and i need to update both Parent element as well as child element.
Thanks.
I understand what you want to do here, but because you are using a DataSet, and I'm guessing that you are defining relations inside your grid ( or you already have relations defined ), because of this, the changes you are making on the grid, are applied onto the underlining data source, the data set.
After that you can use one of the available documents, in order to find out how to update your data as a base reference you could check out this article Updating Data Sources with DataAdapters (ADO.NET), and as for the event on which you should update the data into the db you have a few options:
- RadGridView.CellEndEdit - this executes after each cell is edited
- RadGridView.RowsChanged
- Save button click, etc
Because this is a general .Net question, you should be able to find a lot of answers and solutions on the web on how to Get / Update data.
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga
Thanks for reply.
1. when i edit the child cell and press tab/ enter / click or next cell, the cell value doesnt update.
2. as you told i used both but no success, which event should i used?
i am ushig heararchy grid.
i have given relation programatically.
i have given list object as a datasource to grid
i am using Entity Framwork to interact with database.
my condition is i update parent row cell it must update parent cell
and if i update child cell it must update child.
but i am having 4 four columns i need to update only once.
by cellEndEdit it will update 4 times
Please suggest.
Thanks
In my experience people often change they're mind, so because of this i try, as much as possible to show a Save and Cancel button on the form.
There are a few advantages of doing so, like:
First, you won't call the database excessively, second if you always update the data in the DB what happens when the user makes a mistake? another update if you have some old cached data stored somewhere?
Second, you could easily create an internal list of changed Items (parents + children) and when the user calls a save it will save just the items contained in that list.
If you don't like, or don't agree with this approach, you could do something else, like saving on control leave, so at least like that you will always perform a save when that user "apparently finished" working on that grid.
Best Regards,
Emanuel Varga
I don't believe you understood what Sachin (not Sachi"m") was asking.
He has a RadGrid that is programatically bound to IQueryable types from an Entity Framework context. There is a parent child hierarchy occurring, in which the relationships are also created via code.
Editing the top level, or Master Template, is fine, however when he makes an edit to a template used in the hierarchy, the value does not change in the grid. It remains the same.
It appears that the issue may be one of updating the underlying databinding. How can one update the row's data element?
First i want to apologize to Sachin, for the misspelling, sorry it was really a mistake :(.
Second, I was trying to ask him to try handling the CellEndEdit event this on this other thread he created on this issue, please join us there.
Best Regards,
Emanuel Varga
Cheers.
I know this is an old post, but I ran into this problem and it turns out is was a dbContext error on my part.
I was implementing the following code to create the radGridView datasource.
private void radDateTimePicker1_ValueChanged(object sender, EventArgs e)
{
MOSES_Entities dbNow = new MOSES_Entities();
var invoices = dbNow.t_ClientInvoices.Select(p => p);
this.t_ClientInvoicesbindingSource.DataSource = invoices.ToList();
ClientInvoicesradGridView.DataSource = t_ClientInvoicesbindingSource;
}
As soon as I referenced a dbContext that was scoped to the entire form, my problem went away.
Hope this helps someone in the future.
-Scott
Thank you for writing in the thread. I am sure that it will be helpful to our community.
Please let me know if you have further questions.
Regards,
Hristo
Telerik by Progress