Question Refreshing datagridview

minat

New member
Joined
Dec 14, 2013
Messages
1
Programming Experience
5-10
Hi,


I have a simple Windows app using a single form to manage a table in an Access database.
I have a datagridview on the form that is linked to a bindingsource
and the bindingsource is tied to a tableadapter's getData method.


The logic is setup to save the data after each row that has changed.
This works fine when handling most edits from the user.
But when certain fields change, or new entries saved,
I have some logic that I need to run/test on the whole dataset.
I'm doing this after the update and when it's complete, I need to refresh the grid .
when I try to do this in code after the above has finished I get this error


InvalidArgument=Value of '3' is not valid for 'rowIndex'.




If I don't refresh the grid at that time, then click another test button after it's finished, it works fine.
Of course, that's not a solution.


I've tried numerous variations, but with the same result.




The line that gives the error is when I set the datasource of the bindingsource.

bsTrading.DataSource = taTrading.GetData



This is generally what the stack trace looks like:
at System.Windows.Forms.DataGridViewRow.GetState(Int32 rowIndex)
at System.Windows.Forms.DataGridViewRowCollection.GetRowState(Int32 rowIndex)
at System.Windows.Forms.DataGridViewRowCollection.GetNextRow(Int32 indexStart, DataGridViewElementStates includeFilter)
at System.Windows.Forms.DataGridViewRowCollection.GetNextRow(Int32 indexStart, DataGridViewElementStates includeFilter, DataGridViewElementStates excludeFilter)
at System.Windows.Forms.DataGridView.CorrectRowFrozenState(DataGridViewRow dataGridViewRow, DataGridViewElementStates rowState, Int32 anticipatedRowIndex)
at System.Windows.Forms.DataGridView.OnInsertingRow(Int32 rowIndexInserted, DataGridViewRow dataGridViewRow, DataGridViewElementStates rowState, Point& newCurrentCell, Boolean firstInsertion, Int32 insertionCount, Boolean force)
at System.Windows.Forms.DataGridViewRowCollection.InsertDuplicateRow(Int32 indexDestination, DataGridViewRow rowTemplate, Boolean firstInsertion, Point& newCurrentCell)
at System.Windows.Forms.DataGridViewRowCollection.InsertCopiesPrivate(DataGridViewRow rowTemplate, DataGridViewElementStates rowTemplateState, Int32 indexDestination, Int32 count)
at System.Windows.Forms.DataGridViewRowCollection.InsertCopiesPrivate(Int32 indexSource, Int32 indexDestination, Int32 count)
at System.Windows.Forms.DataGridViewRowCollection.AddCopiesInternal(Int32 indexSource, Int32 count)
at System.Windows.Forms.DataGridView.RefreshRows(Boolean scrollIntoView)
at System.Windows.Forms.DataGridView.RefreshColumnsAndRows()
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.DataSourceMetaDataChanged()
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs e)
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged(Object sender, ListChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)
at System.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e)
at System.Windows.Forms.BindingSource.ResetBindings(Boolean metadataChanged)
at System.Windows.Forms.BindingSource.SetList(IList list, Boolean metaDataChanged, Boolean applySortAndFilter)
at System.Windows.Forms.BindingSource.ResetList()
at System.Windows.Forms.BindingSource.set_DataSource(Object value)




Thanks in advance for your help.
 
Top Bottom