16518

ADGV C# DataGridView - update query bug?

Question:

I'm trying to use auto-generated advancedDataGrid - ADGV (<a href="https://adgv.codeplex.com" rel="nofollow noreferrer">adgv.codeplex.com</a>).

Problem is that the below shown procedure does not succeed with updating the SQL table every time... It is exactly <strong>every second Event</strong> raised...

private void advancedDataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { int rowIdx = advancedDataGridView1.CurrentCell.RowIndex; DataRowView drv = (DataRowView)advancedDataGridView1.Rows[rowIdx].DataBoundItem; DataRow dr = drv.Row; this.levTableAdapter.Update(dr); //strange, but Update is done every second time.... }

How to debug it?, if I add another line of this.levTableAdapter.Update(dr) - it will not help either...

EDIT: Looked into behaviour again and I have to update:

1st enter "A" - noChangeSQL, Event picks "A", "A" in the datagrid cell. 2nd enter "B" - "A" in SQL, Event picks "A", "A" in cell. 3rd enter "C" - "A" in SQL, Event picks "C", "C" in cell. 4rd enter "D" - "C" in SQL, Event picks "C", "C" in cell. 5th enter "E" - "C" in SQL, Event picks "E", "E" in cell.

Answer1:

Are you sure, it's every second event? Could it be it doesn't save just the last row you changed? If it is a timing issue or excecution order problem (like row state update happening after EndEdit event gets handled), you can defer it a bit, with Form's BeginInvoke, like this:

private void advancedDataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { int rowIdx = advancedDataGridView1.CurrentCell.RowIndex; DataRowView drv = (DataRowView)advancedDataGridView1.Rows[rowIdx].DataBoundItem; DataRow dr = drv.Row; BeginInvoke((Action)(() => SaveRowChanges(dr))); } private void SaveRowChanges(DataRow dr) { DataRow[] rows = { dr }; adapter.Update(rows); }

Recommend

  • TextBox - Object Reference Not Set To An Instance of an Object
  • Updating datagridview with mysql
  • How to draw to context without losing it?
  • How to check if datagridview cell is Null
  • CancelEdit does not keep focus on edited cell in DataGridView c#
  • Add decimal point & set cursor position to DataGridView cell text on KeyPress event
  • Parallel array or array of structures [closed]
  • how to set radiogroup radiofield based on the json data extjs 4
  • Storing or loggin data with greasemonkey which can be processed later
  • asp.net GridView IF empty show message
  • dojox.grid.DataGrid: how to access data from a click event?
  • How To Understand dynamic HTML in Visual Studio 2008?
  • Deleting a row completely from a dataset
  • replacing a value in all columns with value of that column
  • revitapi ironpython ToRoom returns “indexer # object”
  • Access variable of ScriptContext using Nashorn JavaScript Engine (Java 8)
  • Connect .sks to skscene.h
  • Debug.DrawLine not showing in the GameView
  • GridView breaks while scrolling
  • Jackson Parser: ignore deserializing for type mismatch
  • How to Cache Real-time Data?
  • How to use RequestBodyAdvice
  • Q promise. Difference between .when and .then
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Incrementing object id automatically JS constructor (static method and variable)
  • Does CUDA 5 support STL or THRUST inside the device code?
  • MySQL WHERE-condition in procedure ignored
  • When should I choose bucket sort over other sorting algorithms?
  • Hazelcast - OperationTimeoutException
  • To display the title for the current loaction in map in iphone
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Akka Routing: Reply's send to router ends up as dead letters
  • AT Commands to Send SMS not working in Windows 8.1
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How do I configure my settings file to work with unit tests?
  • Is it possible to post an object from jquery to bottle.py?
  • Sorting a 2D array using the second column C++
  • java string with new operator and a literal