I have a DataGridView bound to a SortableBindingList(Of T), written based on Custom Data Binding, Part 2. When I set DataSource and call Sort (done in BindDGVs method) I get the exception message "Column provided does not belong to this DataGridView control.".
This is the call that throws:
This is stacktrace:
The grid columns configured in Designer has different AutoSizeMode set, AllCells for the column sorted on. From what I can tell from online searches for the error message AutoSizeMode can be problematic, though it doesn't seem confirmed nor resolved.
If it matters, data loading is done asynchronous from Forms Load event, when done loading BindDGVs is invoked to UI thread, this call always happens after form is Shown.
Anyway I have it resolved, but posted for others that may encounter it, or if someone has some input to this.
This is the call that throws:
VB.NET:
Me.FilterGrid.Sort(Me.colFilterType, System.ComponentModel.ListSortDirection.Ascending)
If I change call to this the Sort is performed without error:System.ArgumentException was unhandled by user code
Message="Column provided does not belong to this DataGridView control."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.DataGridView.Sort(DataGridViewColumn dataGridViewColumn, ListSortDirection direction)
at RSSview.Form1.BindDGVs() in D:\programming\vbnet35\RSSview\RSSview\Form1.vb:line 218
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
InnerException:
VB.NET:
Me.FilterGrid.Sort(Me.FilterGrid.Columns("colFilterType"), System.ComponentModel.ListSortDirection.Ascending)
If it matters, data loading is done asynchronous from Forms Load event, when done loading BindDGVs is invoked to UI thread, this call always happens after form is Shown.
Anyway I have it resolved, but posted for others that may encounter it, or if someone has some input to this.