Infragistics XamTextEditor copy to DataTable (WPF) - c#

I'm working with a XamDataGrid which is bound to a DataTable. When I type in data in the rows and I hit save (to save my data back to the database), it never saves the last row entered. I'm guessing because I need to tab out of the cell that I'm currently entering data in and that it will only move the text to the DataTable upon edit end. Is there a way to copy data to the DataTable as the user enters it so they don't have to tab out to force the edit end or is there a better way? Thanks!

I would add this as comment but am unable to. Its hard to say without more information but have you tried adding UpdateSourceTrigger=PropertyChanged?
"{Binding Path=Something, UpdateSourceTrigger=PropertyChanged}"

The grid should update its source if it loses focus which may not be happening especially if your save button is in a toolbar that doesn't take focus. If that is the case, you can force the grid to end editing and commit the record by calling ExecuteCommand on the XamDataGrid and passing in the DataPresenterCommands.EndEditModeAndCommitRecord command.

Related

Using Radgridview directly for data Manipulation

So i am using RadGridView for Winforms.
Now what i want to do is to perform data manipulation in the radgridview and datasource to get updated after the row loses foucs. I don't want to use textboxes or any other control for entering data.
Something like this
And after i press the new add new row and enter data
Now this data isn't being updated in the dataSource to update i need a query that needs to executed against the datasource.
Now i haven't been able to build a query because i haven't been able to figure out how to access the data of the newly created cells so that i can build a query and pass to SQLCeDataAdapter for execution.
Any pointers will be appreciated.
Im not sure about RadGridView, but I use DataGridView, wich I guess works the same way
You need to get the datarow so u can update to the database
DataRow row = ((DataRowView)eTipoDocumentoBindingSource.Current).Row;
once you have it, you can use the DataTableAdapter method update(row) to save changes to the database
You can do that, either in the click event of a save button, or in the event of focused row changed

C# datagridview editing control

I have an application that has a datagridview in it obviously enough, and I add data to it programatically like so:
dataGridView1.Rows.Add(string[]);
Before I add any objects to the dataGridView I can edit the cells by double clicking, hitting enter or f2. After data has been added into the rows however, I can no longer edit any of the values. I have tried toggling the "Read Only" attribute from true to false, and also tried to mess with:
dataGridview1.EditMode ....
I don't know how to make the edit mode work properly, but on all previous keystrokes it just highlights the next row in the list.
How can I enable the user to edit the data in the data grid view once the rows have been added ?
Here are a list of tutorials on ways to accomplish this here:
http://www.codeproject.com/Questions/433279/edit-delete-update-cancel-in-gridview-asp-net
I would start with these.

DataGrid problems. Using DataSet.Merge with "Edit Template"

I am trying to debug an issue with a WinForm application.
The application uses a DataGridView bound to a DataSet.
The user can select a row and click "Edit" and an Edit Form appears so the user can edit the row and save his changes.
If the DataGridView is sorted by one or more columns and the user edits a row more than once and changes that rows position in the DataGrid (by changing one of the sorted columns TWICE), the DataGridView gets out of sync and I get Exception errors.
Here is how the code is written:
When the user clicks a row and hits edit (the user may only select one row), that row is passed to the EditFom. The edit Form creates an empty DataSet and loads that Row. When the user is done, the calling form uses DataSet.Merge to merge those changes back into its DataSet.
Here are a couple of scenarios that tell me it is womething to do with the "merge" and sorting:
(Note, I never change the actual "sorting", I am talking about changing the value of one of the sorted by columns in one of the rows.)
If the user edits a row directly in the Grid and changes the value of one of the columns being used to sort, then changes it again, etc. The row moves around the Grid, like it should and when the user clicks save, everything saves fine.
If the user edits a row (directly in the Grid OR via the "template") and doesnt change any of the "sort" columns, just makes an edit (therby setting the "State" of the row to Modified, right...), THEN the user edits the row using the Template (which goes through the seperate DataSet and merges the data back when done), and changes one of the columns being sorted (when done, the grid should resort and the row should "move"), the row doesn't get REPAINTED, it stays in the same position in the grid that it was in before the template edit. (Although, the data saves fine and you can refresh the grid and it sorts properly.) Evidently, the DataGrid isn't being notified that the RowChanged in this scenario (or it is, but it isn't doing anything about it).
If the user edits a row directly in the Grid, change a sort column (the row moves), then edits the row using the template and changes that column again, we get the same results as 2, above. The data saves fine, but when the user leaves the edit template, the grid doesn't resort.
(This is the one that causes the Exception error.)
If the user edits a row using the template and changes a sort column and leaves the template, the datagrid resorts and the row moves properly. Then, if the user edits the SAME row using the Template Edit and changes the sort column AGAIN. When the user leaves the edit template, the datagrid doesn't resort and when the user saves the data and the grid refreshes, we get an error:
System.InvalidOperationException: DataTable internal index is corrupted: '5'.
And sometimes, we get an error complaining the primary key is missing.
Any advice on how to "debug" this? I feel like it has something to do with the "internediate" dataset the edit template uses and the "Merge". It is like the DataGrid datasource is getting out of sync with the DataGrid Rows.
I should have done some Google'ing before posting this. It seems to be a common error and I found a HUGE post about this on the MS site. Unfortunately, I haev tried most of their suggestions, but most likely I will find my answer there. I just wanted to make a note of this, in case anyone is interested:
http://social.msdn.microsoft.com/Forums/en/adodotnetdataproviders/thread/18544cd3-1083-45fe-b9e7-bb34482b68dd

update data grid view automatically

I have two windows forms. The first form shows list of records from sql. When you click some cell of a record in DataGridView it shows the second form. In the second form you can edit and update the record. I want DataGridView to be
updated automatically when user close second form. What should I do?
Are you using data bindings, or do you manually fill the grid ? With data bindings its very easy... if the data is contained in a DataTable and you change it somewhere, the change will be reflected automatically in the DataGridView. It also works with objects that implement INotifyPropertyChanged, and lists that implement IBindingList.
If you're not using bindings, you can :
locate the cell that contains the edited value, and update it manually, OR
refill the entire grid
Fill the grid with data from the database again?

How do I smoothly update a GridView by updating the bound DataTable in C#?

I have a GridView who's DataSource is set to a DataTable. The DataTable is updated by some backend logic every few seconds, at which point a delegate is called to refresh GridView.
Currently I am simply resetting the DataSource, but that causes a problem - it interrupts any ongoing edits in the grid view and makes the selection 'jump' to the top-left cell.
The update logic basically creates a new (identical with regard to columns and rows) DataTable.
Is there any standard way to do it without any drawbacks? Is my only option updating the current DataSource row by row, inserting values programmatically?
Thanks!
You should use a BindingList or some data source that supports change notification.
I'm confused by many things in this question. If you're using a GridView, and not a DataGridView, then you're either using ASP.NET, WPF, or .NET 1.1. Which is it?
Next: you're creating a new DataTable entirely? Well of course the control's going to get reset when you reset the DataSource. It doesn't know that the schema of your new DataTable is the same as the one it's replacing. It's got to go through the columns and re-establish the bindings.
Also, of course it's losing the current row. The current row belongs to the old DataTable, not the new one.
If you want a bound control to retain its state when you update the underlying data source, update the underlying data source, don't replace it with a new one.
Do your updates happen on a background thread? I don't know if it will work in your scenario, but you could try this threaded binding list; see the example to see the worker merrily editing the grid.

Categories