adding a columnGroup at run time

6 posts, 0 answers
  1. Joe
    Joe avatar
    48 posts
    Member since:
    Feb 2012

    Posted 06 Jan Link to this post

    Hello;

     

    In your WPF control it looks like you can do this:

    https://www.telerik.com/forums/how-to-add-columngroup-in-radgridview-columngroups-at-run-time-from-code-behind

     

    How can I add a new columnGroup to the current ViewDefinition?

     

    Thank you,

     

    Joe

  2. Joe
    Joe avatar
    48 posts
    Member since:
    Feb 2012

    Posted 06 Jan in reply to Joe Link to this post

    I seem to *almost* have it working with this:

     

    ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();
               view = (ColumnGroupsViewDefinition)transactions_grid.MasterTemplate.ViewDefinition;
               view.ColumnGroups.Add(new GridViewColumnGroup("New Group"));
               view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
     
              
               GridViewTextBoxColumn newColumn = new GridViewTextBoxColumn("holder");
               newColumn.HeaderText = "Place Holder";
               transactions_grid.Columns.Add(newColumn);
     
               view.ColumnGroups[0].Rows[0].ColumnNames.Add("holder");
               transactions_grid.ViewDefinition = view;

     

    But I get a 

    System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'

    KeyNotFoundException: The given key was not present in the dictionary.

     

    thrown on the Application.Run(new RadForm1())

    ??

     

  3. Joe
    Joe avatar
    48 posts
    Member since:
    Feb 2012

    Posted 06 Jan in reply to Joe Link to this post

    I almost have it working with the following code:

    private void add_subgroup_btn_Click(object sender, EventArgs e)
            {
                
                ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();
                view = (ColumnGroupsViewDefinition)transactions_grid.MasterTemplate.ViewDefinition;
                view.ColumnGroups.Add(new GridViewColumnGroup("New Group"));
                view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
     
               
                GridViewTextBoxColumn newColumn = new GridViewTextBoxColumn("holder");
                newColumn.HeaderText = "Place Holder";
                transactions_grid.Columns.Add(newColumn);
     
                view.ColumnGroups[0].Rows[0].ColumnNames.Add("holder");
                transactions_grid.ViewDefinition = view;
     
     
            }

     

    But I get a 

    System.Reflection.TargetInvocationException
      HResult=0x80131604
      Message=Exception has been thrown by the target of an invocation.
      Source=mscorlib
      StackTrace:
       at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
       at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
       at System.Delegate.DynamicInvokeImpl(Object[] args)
       at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
       at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       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()
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at Telerik.WinControls.RadControl.WndProc(Message& m)
       at Telerik.WinControls.UI.RadGridView.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 Flex_Billing_Console.Program.Main() in E:\Local Source Control\DDP Flex\Flex Billing Console\Flex Billing Console\Program.cs:line 17

    Inner Exception 1:
    KeyNotFoundException: The given key was not present in the dictionary.

  4. Joe
    Joe avatar
    48 posts
    Member since:
    Feb 2012

    Posted 06 Jan in reply to Joe Link to this post

     almost have it working with the following code:
    private void add_subgroup_btn_Click(object sender, EventArgs e)
            {

                ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();
                view = (ColumnGroupsViewDefinition)transactions_grid.MasterTemplate.ViewDefinition;
                view.ColumnGroups.Add(new GridViewColumnGroup("New Group"));
                view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());


                GridViewTextBoxColumn newColumn = new GridViewTextBoxColumn("holder");
                newColumn.HeaderText = "Place Holder";
                transactions_grid.Columns.Add(newColumn);

                view.ColumnGroups[0].Rows[0].ColumnNames.Add("holder");
                transactions_grid.ViewDefinition = view;


            }

    But I get a 
    System.Reflection.TargetInvocationException
      HResult=0x80131604
      Message=Exception has been thrown by the target of an invocation.
      Source=mscorlib
      StackTrace:
       at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
       at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
       at System.Delegate.DynamicInvokeImpl(Object[] args)
       at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
       at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       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()
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at Telerik.WinControls.RadControl.WndProc(Message& m)
       at Telerik.WinControls.UI.RadGridView.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 Flex_Billing_Console.Program.Main() in E:\Local Source Control\DDP Flex\Flex Billing Console\Flex Billing Console\Program.cs:line 17

    Inner Exception 1:
    KeyNotFoundException: The given key was not present in the dictionary.
  5. Joe
    Joe avatar
    48 posts
    Member since:
    Feb 2012

    Posted 07 Jan Link to this post

    Sorry for the duplicate posts.  It kept saying "sorry - something went wrong!" -- but then it wound up posting multiple times.  You would think that by now these groups would allow editing or deleting your own posts.
  6. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    2946 posts

    Posted 08 Jan Link to this post

    Hello, Joe,  

    Thank you for writing.  

    If you need to add a new column to the applied ColumnGroupsViewDefinition of RadGridView, it is necessary to create a new instance of the ColumnGroupsViewDefinition and add all of the existing columns together with the new column. Then, apply this new instance of the ColumnGroupsViewDefinition to the RadGridView.ViewDefinition property.

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top