none
Datagridview, bindingsource, thread problem RRS feed

  • Question

  • I have a datagridview with a bindingsource as a datasource. the datasource of the bindingsource is a datatable from a dataset.

    When a change occurs in the datatable .. i get notify ... when i get notify i applied the changes in my cache version of the datatable where the bindingsource is pointing.

    i get the following exception :
    System.IndexOutOfRangeExceptions: Index 0 does not have a value
    at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
    at System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetError(Int32 rowIndex)


    I think it's due to a thread problem .. since the datatable is only thread safe on read-only and not write.

    Do you have a suggestion to overcome that issue?
    Monday, October 16, 2006 9:12 PM

Answers

  • I found a way to fix it. By invoking a delegate from the main thread. the main thread will update the dataset. and there's no more problem there.
    Tuesday, October 17, 2006 1:55 PM

All replies

  • I found a way to fix it. By invoking a delegate from the main thread. the main thread will update the dataset. and there's no more problem there.
    Tuesday, October 17, 2006 1:55 PM
  • I have the same problem as the first user had, and tried to fix it but it still come back. would you please post more detailed solution here.

    thank you

    Monday, February 5, 2007 8:14 PM
  • The problem comes from the fact that when receiving a event, the notification was on another thread. Thus the other thread was modifying dataset which the bindingsource was bound to. To resolve this issue, I use Invoke, to invoke the methods that changes data so that it will be done in the UI thread.

    I hope it helps.
    Wednesday, February 7, 2007 8:03 PM
  • Hi GoDaddy,

     

    I have the same error on my app using the datagridview. My app receives an event and on that event it changes the datagridview datasource using the bindingsource which contains a datatable. Actually, it updates the (dgv) datagridview datasource but after updating the dgv datasource, I have the next lines of codes to update the boldeddates on my MonthCalendar control. What happens is that the MonthCalendar control doesn't show and my app hangs.

     

    Can you show me a sample code on which part of the code to insert the invoke methods, in C#?

     

    Hope to hear from you soon.

    Thursday, March 6, 2008 7:07 PM
  • You could try this.

    Debug your app. And check the Thread on which all the modification is done, if it's not on your UI Thread, its prolly the reason why you are experiencing that issue.

    Thus, you must sync your call back to the UI Thread.

    example in a winForm :

    Code Snippet

    this.Invoke( new MethodInvoker( delegate()
                 {
                        //code that modify ui controls  
                 } ), null );


    Hope it helps
    Monday, March 10, 2008 5:15 PM