Our DataGrid-heavy application likes to throw exceptions when double-clicking the space between rows used for resizing. The exception is The " DataGridColumnStyle cannot be used because it is not associated with a Property or a Column in the DataSource.
Most of our DataGrid-based forms inherit from one form called GridForm. Our DataSource is a DataView. I can set a breakpoint in our double-click event handler, but it's never reached. The except is caught at the Show/ShowDialog call of the entire form hosting the control. We are now running .NET 3.5, but most of this functionality was built in .NET 1.1. We had the same problem back then as well.
StackOverflow's very own Joel Coehoorn seems to have run into the same problem here: http://discuss.fogcreek.com/dotnetquestions/default.asp?cmd=show&ixPost=5780
This is a bug we've had lurking around for a good 3-4 years, so solving this would be amazing.
Here's the full exception: The DataGridColumnStyle it's complaining about differs between each grid in our application. I'm guessing this means that we have a column style that displays a column that isn't in the bound data set. The columns included in a data set will change depending on the needs for a given form, so we really do need to define some styles for columns that could or could not be there.
System.InvalidOperationException: DataGridColumnStyle of 'Real-Time Bill' cannot be used because it is not associated with a Property or Column in the DataSource.
at System.Windows.Forms.DataGridColumnStyle.CheckValidDataSource(CurrencyManager value)
at System.Windows.Forms.DataGridColumnStyle.GetColumnValueAtRow(CurrencyManager source, Int32 rowNum)
at System.Windows.Forms.DataGridBoolColumn.GetColumnValueAtRow(CurrencyManager lm, Int32 row)
at System.Windows.Forms.DataGrid.RowAutoResize(Int32 row)
at System.Windows.Forms.DataGrid.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at CLS.Presentation.MainForm.Main(String[] args) in C:\Users\stuartb.CLS\Documents\Projects\Genesis\CLS.Presentation\MainForm.cs:line 2712
As requested, here's the definition for the column in question. Granted, it's not always this column that the exception indicates. As noted in my previous edit, column styles that look for a column that is not in the bound DataTable cause this problem. In this example, ConsumptionBill is not in the bound DataTable. The behavior in this case is simply to have the column not be shown, and apparently crash and burn on row border double-clicks.
this.dataGridBoolColumnClientsConsumptionBill.Alignment = System.Windows.Forms.HorizontalAlignment.Center;
this.dataGridBoolColumnClientsConsumptionBill.AllowNull = false;
this.dataGridBoolColumnClientsConsumptionBill.HeaderText = "Real-Time Bill";
this.dataGridBoolColumnClientsConsumptionBill.MappingName = "ConsumptionBill";
this.dataGridBoolColumnClientsConsumptionBill.Width = 75;