I have created a WinForm that takes data from another application and saves it in a database. I use a BindingNavigator (I dragged the dataset table onto my form and got a navigator, bindingsource and more) to display and navigate through the records.
When records are added to the dataset/table the BindingNavigator doesn't update itself with the new info right away. It is like nothing was added.
I have to click on the BindingNavigator's next item, previous item or things like that so it will refresh itself and show the correct number of items.
Can someone tell me how I programmatically tell the BindingNavigator to show the updated values?
I have tried a lot of things but nothing has worked.
EDIT
I figured out what was going wrong. I was running on a different thread than the form.
Code that worked for me:
this.tableAdapterManager.PieceTableAdapter.Insert(ints[4], ints[2], ints[6], ints[8], ints[10], ints[12], ints[14]);
this.tableAdapterManager.UpdateAll(this.slicerTestDBDataSet);
this.pieceBindingNavigator.Invoke(new Action(() => this.pieceTableAdapter.Fill(this.slicerTestDBDataSet.Piece)));
Earlier I didn't use Invoke to invoke the main thread so it didn't work properly.
First thing to do is check the update and insert statements are in the command text of the tableadapter. Click on the tableadapter in the design view if the dataset and see the properties. In the properties you will see the update and insert sections with a + on the left. Expand this to see the command text. If it is empty, then go back to the right click of the table adapter and select configure. Then look at the query designer and make sure everything in the table you want to update is checked. Then finish the wizard and go back and make sure the wizard created the insert and update statements.
I have found that sometimes one textbox will accept an update and others won't. I fixed this by deleting the textbox and adding a new textbox that I would rebind.
Related
Hi guys I searched for lot on this topic but don't get any result. I want to know it is possible to add, update, delete inside datagridview in c# means i want to add new row and data inside the editable datagridview not from the forms control. I want to place Add New, edit, delete button or anything inside datagridview. In google there is lot of tutorials for this but from the form controls. This is possible in gridview control but i want to know this is also possible in datagridview or not If you have any link related to this then plz inform me. Thanks in advance!
You can Add new DataSet to your project, drag into it by DataSet Designer the table that you want edit with DataGridView by drag and drop from the Server Explorer to DataSet Designer, the runtime will create all the action to interact with you Dataset and TableAdapter, back into Form designer open Data Source Panel Drag your table under dataset to your Form .... done!
Next step it will call Update Method by single button here is the code:
this.nameOfYourTableAdapter.Update(this.nameOfYourDataSet.nameOfYourTable);
ref: Microsoft MSDN
In my application I have two datagrids connected to DB by Entity Framework. First datagrid is used only to select worker, second datagrid is to add, remove, update previous selected workers training's. Please check the screenshot for better view.
Problem is that whenever I add or remove rows from second datagrid (with training's) It's not updating rows, it update database, but datagrid control stays the same. Modifying rows works good.
What I have done while trying to solve this:
1. Checking for stupid code mistakes (misspeling etc)
2. Force to update Itemsource with : OnPropertyChanged("ToolboxList");
3. Breakpoint everything and it works...
But datagrid rows are the same...
Some clues that might be the reason but I am not sure if they are problem makers here:
enovaWorkers its not a table its a view, hr_ToolboxTalk its a table, and because you can't make association view to table they are associated with one to many pragmatically inside EF edmx file.
Second datagrid is not binded by selection from first datagrid (SelectedWorker.hr_ToolboxTalk) because whenever you want to edit row in second grid it raises Edit is not allowed exception. This is described here: master detail datagrid not editable
And since I cant and don't want to edit entitiy framework tt file I made workaround with GetToolboxTalkList() method. So please check the code.
Pasted code (some sections are cuted):
XAML : pastebin.com/h3sdbfKm
ViewModel: pastebin.com/7Vj3P5UJ
ICommand class: pastebin.com/rQAh7FM9
Thanks for the help...
Change:
List<hr_ToolboxTalk> ToolboxList;
to:
ObservableCollection<hr_ToolboxTalk> ToolboxList;
It will work, Lists dont Notify to the view Automaticaly.
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
I'm in C# Express 2010 and SQL Server Express 2008, making a winforms front end for simple table editing. User picks a table from a combobox, and a datagridview is populated with that table. There's a Submit and Reload button at the bottom of the form. It's loosely based on Microsoft's example for binding a DGV to a database.
So, I have this datagridview that is populated by a data adaptor. After it's been populated, I go through the resulting table and replace any columns with foreign keys with comboboxcolumns so it's easier for the user.
This bit all works fine. The comboboxcolumn shows up, with the correct data in it etc etc. I've set the Headertext, DataProprtyName, and Name properties to match the column it has replaced.
It DOES seem to have broken my 'submit' button that does the update command. Basically, if I change the value in one of the comboboxcolumns, I get a concurrency violation. If I change a value in any other column, it silently fails (when the data is reloaded into the DGV, the updated value vanishes).
Any ideas what the problem could be here?
If you need to see code just let me know. There's rather a lot of it as I'm a newbie and have probably done things in a horrendously messy way!
Thanks in advance.
Never mind - I figured it out - I had copy/pasted a procedure and forgotten to create a new DataAdaptor, so it was using the same one as the one used to populate the DGV, hence things went A over T...
I have a DataGridView that allows users to enter new information. Using subsonic I Save the new info to the database. And this works correctly. My problem is that after the Save is done the newly added row disappears from the grid. I tried to Reload the form, but I get the following error:
Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.
I don't think the issue is subsonic related. Does anyone know why the newly added row disappears?
Thanks
The reason was that I broke the binding connection by using ".ToTable()"
kek444 - thanks for the reply. Don't think that will help. I'm not using _CellEndEdit but instead using _RowValidating. I've also tried _RowLeave and others. I don't really want to reload the form - I just don't know why the newly entered values disapper when the row loses focus.