This project is read-only.

Clicking on column header on a column containing images causes crash

Jul 12, 2012 at 4:53 PM


I created a table, where one column contains images.  The images display nicely, so no problem there.

The problem is that when I click on the column header for the column containing images, the system throws crash.  The default comparing function built into SourceGrid does not know how to deal with sorting images.  I would have it do nothing, when dealing with columns of images, but SourceGrid crashes.

How do I solve the problem?

I did find an existing discussion created back in 2009, which uses the SourceGrid.SortRangeRows method to create a custom comparer.  The first argument is a new Range class.  The problem that I see using that is that the the maximum number of rows changes, but the sort should still work.  Also, this method seems overtly complex to simply handle a crash.

Can I disable sorting on a particular column?  If so, how?

What is the bet way to resolve this issue?  How?

Thanks in advance,e


Jul 16, 2012 at 4:46 PM

>>The problem is that when I click on the column header for the column containing images, the system throws crash.

What is the problem? is it SourceGrid code that is throwing exception, or your code? Do you have the stack-trace?

See example 29, there you can sort column with images, works fine.


>> Can I disable sorting on a particular column?  If so, how?


Sure. See example 14, just use AutomaticSortEnabled proprety, and set it to false. It removes SortableHeader controller from the cell


private void frmSample14_Load(object sender, System.EventArgs e)
            grid1.BorderStyle = BorderStyle.FixedSingle;

            grid1.ColumnsCount = 4;
            grid1.FixedRows = 1;

            SourceGrid.Cells.Editors.ComboBox cbEditor = new SourceGrid.Cells.Editors.ComboBox(typeof(string));
            cbEditor.StandardValues = new string[]{"Value 1""Value 2""Value 3"};
            cbEditor.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.AnyKey;

            var header = new SourceGrid.Cells.ColumnHeader("String");
            header.AutomaticSortEnabled = false;
            grid1[00] = header;
            grid1[01] = new SourceGrid.Cells.ColumnHeader("DateTime");
            grid1[02] = new SourceGrid.Cells.ColumnHeader("CheckBox");
            grid1[03] = new SourceGrid.Cells.ColumnHeader("ComboBox");
            for (int r = 1; r < 10; r++)
                grid1[r, 0] = new SourceGrid.Cells.Cell("Hello " + r.ToString(), typeof(string));
                grid1[r, 1] = new SourceGrid.Cells.Cell(DateTime.Today, typeof(DateTime));
                grid1[r, 2] = new SourceGrid.Cells.CheckBox(nulltrue);
                grid1[r, 3] = new SourceGrid.Cells.Cell("Value 1", cbEditor);
                grid1[r, 3].View = SourceGrid.Cells.Views.ComboBox.Default;



Jul 18, 2012 at 12:58 AM

Thanks for the reply!

Here is the exception information

 Failed to compare two elements in the array.

 {Void SwapIfGreaterWithItems(Int32, Int32)}


Inner Exception
 {"Invalid cell object, no IComparable interface found"}


Stack Trace
   at System.Array.SorterObjectArray.SwapIfGreaterWithItems(Int32 a, Int32 b)
   at System.Array.SorterObjectArray.QuickSort(Int32 left, Int32 right)
   at System.Array.Sort(Array keys, Array items, Int32 index, Int32 length, IComparer comparer)
   at SourceGrid.Grid.OnSortingRangeRows(SortRangeRowsEventArgs e)
   at SourceGrid.GridVirtual.SortRangeRows(Range p_Range, Int32 keyColumn, Boolean p_bAscending, IComparer p_CellComparer)
   at SourceGrid.Cells.Controllers.SortableHeader.SortColumn(CellContext sender, Boolean p_bAscending, IComparer p_Comparer)
   at SourceGrid.Cells.Controllers.SortableHeader.OnMouseUp(CellContext sender, MouseEventArgs e)
   at SourceGrid.Cells.Controllers.ControllerContainer.OnMouseUp(CellContext sender, MouseEventArgs e)
   at SourceGrid.Cells.Controllers.CellEventDispatcher.OnMouseUp(CellContext sender, MouseEventArgs e)
   at SourceGrid.Cells.Controllers.ControllerContainer.OnMouseUp(CellContext sender, MouseEventArgs e)
   at SourceGrid.GridVirtual.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.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(IntPtr 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 AdminConsole.Program.Main() in C:\SoftDev\Projects\Stamping\Versions\Current\Stamp\AdminConsole\Program.cs:line 38

Jul 18, 2012 at 11:13 PM

Hello Sarah,

I modified Sample14 changing the checkbox cells to image cells and setting AutomaticSortEnabled to false for its column header.  I populated the image cells with two different images, FACE00 and FACE01 from the resources folder.  Additionally, once the application was running, I was able to change image cells to other images from the resource folder as well.  Sorting works as expected without the exception you are experiencing.

Sample41 includes images in data.cell(s) which also sort correctly.

I was able to create the exception only by enabling automatic sorting and selecting the image column header as the sort key.

Hope this helps.


Jul 19, 2012 at 3:44 PM
Edited Jul 19, 2012 at 3:47 PM

I looked at sample 29, which was not all that obvious and easy to find, if I might add.

Also, I now switched to version 4.40.  That was also not obvious that there was a new version out.  I would have a mailing list of users.

I see two differences between what I am doing and sample 29.

1. The sample uses SourceGrid.DataGrid, whereas I am using SourceGrid.Grid.

2. The sample defines by column and I define a column by cell.

Sample:  see CreateColumns() in frmSample29.cs.  (a bit too long for copy and paste)


Old (previous to trying to merge with sample)

this.ctlTable[iRow, iColumn] = new SourceGrid.Cells.Image(oValue);
this.ctlTable[iRow, iColumn].View = new SourceGrid.Cells.Views.MultiImages();

New (merged with sample a bit)

SourceGrid.Cells.Views.Cell viewImage = new SourceGrid.Cells.Views.Cell();
viewImage.BackColor = Color.DarkSeaGreen;
viewImage.Border = null;
viewImage.ImageStretch = false;
viewImage.ImageAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
this.ctlTable[iRow, iColumn] = new SourceGrid.Cells.Image(oValue);
this.ctlTable[iRow, iColumn].View = viewImage;
SourceGrid.DataGridColumn gridColumn;

The "old" and "new" methods both fail when sorting an image column.  All other non-image columns sort fine with no crash.

Jul 19, 2012 at 3:58 PM
Edited Jul 19, 2012 at 4:21 PM

One more thing to my just now posted reply, I am able to use AutomaticSortEnabled to turn off sorting on the image column, however that is sort of bandaiding the problem.

I would prefer to get clicking on a column that contains images to not crash, because it cannot find an IComparer for that column.