This is a migrated thread and some comments may be shown as answers.

adding a columnGroup at run time

5 Answers 86 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Joe asked on 07 Jan 2018, 02:55 AM

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

5 Answers, 1 is accepted

Sort by
0
Joe
Top achievements
Rank 2
answered on 07 Jan 2018, 03:21 AM

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())

??

 

0
Joe
Top achievements
Rank 2
answered on 07 Jan 2018, 03:22 AM

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.

0
Joe
Top achievements
Rank 2
answered on 07 Jan 2018, 03:23 AM
 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.
0
Joe
Top achievements
Rank 2
answered on 07 Jan 2018, 12:34 PM
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.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Jan 2018, 12:55 PM
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.
Tags
GridView
Asked by
Joe
Top achievements
Rank 2
Answers by
Joe
Top achievements
Rank 2
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or