Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 307749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:35:13+00:00 2026-05-12T07:35:13+00:00

Our DataGrid-heavy application likes to throw exceptions when double-clicking the space between rows used

  • 0

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;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:35:14+00:00Added an answer on May 12, 2026 at 7:35 am

    Thanks to a little guided digging, with help from John, I was able to resolve the issue generally with the following method.

    IList<DataGridColumnStyle> missingColumnStyles = new List<DataGridColumnStyle>();
    /// <summary>
    /// Adjust the grid's definition to accept the given DataTable.
    /// </summary>
    /// <param name="table"></param>
    protected virtual void AdjustGridForData(DataTable table, DataGrid grid)
    {
        // Remove column styles whose mapped columns are missing.
        // This fixes the notorious, uncatchable exception caused when double-clicking row borders.
        var columnStyles = grid.TableStyles[table.TableName].GridColumnStyles;
    
        // Add previously removed column styles back to the grid, in case the new bound table
        // has something we removed last time this method was executed.
        foreach (var missingColumnStyle in missingColumnStyles)
            columnStyles.Add(missingColumnStyle);
        missingColumnStyles.Clear();
    
        // Move the offending column styles into a separate list.
        var missingColumns = new List<string>();
        foreach (DataGridColumnStyle style in columnStyles)
        {
            if (!table.Columns.Contains(style.MappingName))
                missingColumns.Add(style.MappingName);
        }
        foreach (var column in missingColumns)
        {
            missingColumnStyles.Add(columnStyles[column]);
            columnStyles.Remove(columnStyles[column]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 138k
  • Answers 138k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you write your own method to do it. public… May 12, 2026 at 7:35 am
  • Editorial Team
    Editorial Team added an answer the :id field is not accessible for mass-assignment. you need… May 12, 2026 at 7:35 am
  • Editorial Team
    Editorial Team added an answer If you use jQuery UI's sortable plugin you can then… May 12, 2026 at 7:35 am

Related Questions

In our application we have style sheets to define common colors etc… I wrote
In our current WinForms app, we are displaying millions of records in ListView, using
I'm still new with C#, and I'm working on a project where we also
I have to develop a tool in C# that retrieves some data from an
Basically I'm going to go a bit broad here and ask a few questions

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.