Home Forums WinForms controls Xceed Grid for WinForms Error When Resizing Columns

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15901 |

    Hi , i wrote a helper class that resizes columns after databinding, so as white space will be filled by last visible column.

    Code is as follows

    public class XceedGridHelper
    {
    public static void ResizeGrid(GridControl dg)
    {
    int totalWidth;
    try
    {
    /*Code should not throw exception but it does throw*/
    totalWidth = dg.DisplayRectangle.Width;
    }
    catch(Exception ex)
    {
    Console.WriteLine(ex.ToString() + ” ” + ex.StackTrace);
    }
    totalWidth = dg.DisplayRectangle.Width;
    int rowSepatorWidth = dg.RowSelectorPane.Width;
    int fixedColumnSplitterWidth = dg.FixedColumnSplitter.Width;
    int totalSize = totalWidth – (rowSepatorWidth +
    fixedColumnSplitterWidth + 50);

    Column lastColumn = null;
    foreach (Column column in dg.Columns)
    {
    if (column.Visible)
    {
    if (lastColumn == null || (column.VisibleIndex > lastColumn.VisibleIndex))
    {
    lastColumn = column;
    }
    totalSize = totalSize – column.Width;
    }
    }

    if (lastColumn != null && lastColumn.Visible)
    lastColumn.Width = lastColumn.Width + (totalSize);
    }

    }

    When i call this method from a form that has GridControl, Code throws exception ( where i wrote comment)

    when i write “totalWidth = dg.DisplayRectangle.Width;” twice (one in try catch block which will not work, and another that will work)

    It is strange, that i wasnt getting this error in the morning, i only added Column Added event to grid, nothing else changed. But Program started to throw exception.

    Exception Stack Trace as Follows

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.InvalidCastException: Unable to cast object of type ‘System.Data.DataViewManagerListItemTypeDescriptor’ to type ‘Entities.Product’.
    at Windows.Forms.winFromStockWatch.winFromStockWatch_ValueChanged(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\Windows.Forms\WinFromStockWatch.cs:line 143
    — End of inner exception stack trace —
    at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
    at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags inA first chance exception of type ‘System.InvalidCastException’ occurred in Windows.Forms.dll
    A first chance exception of type ‘System.Reflection.TargetInvocationException’ occurred in Xceed.Grid.dll
    vokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
    at System.Delegate.DynamicInvokeImpl(Object[] args)
    at System.Delegate.DynamicInvoke(Object[] args)
    at Xceed.Grid.GridElementBase.RaiseEvent(Object eventKey, EventArgs e)
    at Xceed.Grid.Cell.OnValueChanged(EventArgs e)
    at Xceed.Grid.Cell.InvokeOnValueChanged(Boolean adviseParent)
    at Xceed.Grid.Collections.CellList.OnItemCreatedFromTemplate(Int32 index)
    at Xceed.Grid.Collections.VirtualListBase.GetVirtualItem(Int32 index, Boolean& isWeakReferenced)
    at Xceed.Grid.Collections.VirtualListBase.GetVirtualItem(Int32 index)
    at Xceed.Grid.Collections.VirtualListBase.ListGetItem(Int32 index)
    at Xceed.Grid.Collections.VirtualListBase.Enumerator.get_Current()
    at Xceed.Grid.CellRow.GetFittedDisplayHeight(AutoHeightMode mode, Graphics graphics, Boolean printing)
    at Xceed.Grid.PaintManager.GetRowHeight(Row row, Graphics graphics)
    at Xceed.Grid.PaintManager.GetBottomPageRowCount(Graphics graphics)
    at Xceed.Grid.PaintManager.CalculateGridRectangleAdjustedToScrollBar(Graphics graphics, Rectangle& gridRectangle)
    at Xceed.Grid.PaintManager.Update()
    at Xceed.Grid.PaintManager.get_VerticalScrollRequired()
    at Xceed.Grid.PaintManager.GetGridClientRectangle()
    at Xceed.Grid.GridControl.get_DisplayRectangle()
    at Windows.Forms.XceedGridHelper.ResizeGrid(GridControl dg) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\XceedGridHelper.cs:line 16 at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
    at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
    at System.Delegate.DynamicInvokeImpl(Object[] args)
    at System.Delegate.DynamicInvoke(Object[] args)
    at Xceed.Grid.GridElementBase.RaiseEvent(Object eventKey, EventArgs e)
    at Xceed.Grid.Cell.OnValueChanged(EventArgs e)
    at Xceed.Grid.Cell.InvokeOnValueChanged(Boolean adviseParent)
    at Xceed.Grid.Collections.CellList.OnItemCreatedFromTemplate(Int32 index)
    at Xceed.Grid.Collections.VirtualListBase.GetVirtualItem(Int32 index, Boolean& isWeakReferenced)
    at Xceed.Grid.Collections.VirtualListBase.GetVirtualItem(Int32 index)
    at Xceed.Grid.Collections.VirtualListBase.ListGetItem(Int32 index)
    at Xceed.Grid.Collections.VirtualListBase.Enumerator.get_Current()
    at Xceed.Grid.CellRow.GetFittedDisplayHeight(AutoHeightMode mode, Graphics graphics, Boolean printing)
    at Xceed.Grid.PaintManager.GetRowHeight(Row row, Graphics graphics)
    at Xceed.Grid.PaintManager.GetBottomPageRowCount(Graphics graphics)
    at Xceed.Grid.PaintManager.CalculateGridRectangleAdjustedToScrollBar(Graphics graphics, Rectangle& gridRectangle)
    at Xceed.Grid.PaintManager.Update()
    at Xceed.Grid.PaintManager.get_VerticalScrollRequired()
    at Xceed.Grid.PaintManager.GetGridClientRectangle()
    at Xceed.Grid.GridControl.get_DisplayRectangle()
    at Windows.Forms.XceedGridHelper.ResizeGrid(GridControl dg) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\XceedGridHelper.cs:line 16

    Imported from legacy forums. Posted by gta7001 (had 2082 views)

    Xceed Support
    Member
    Post count: 5658

    Did you had your function to the Column Added event?

    If yes, what might have happened is that your function is run once for each of the column. The problem is that if there already is 1 extra large column, it will take that “extra large” part off the totalSize variable; giving negative values to other column’s width value.

    Imported from legacy forums. Posted by CharlesB (had 3318 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.