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

Editing gridviewcomboboxcolumn

6 Answers 244 Views
GridView
This is a migrated thread and some comments may be shown as answers.
josephine shirley
Top achievements
Rank 1
josephine shirley asked on 16 Aug 2010, 06:14 AM
Hi,

I am having a scenario that I need to enter a new value to the field or select a existing value in the combo box. On change of the cell selection I need to insert or update the value in the database.

The issue is

Im able to enter new value to the combobox ,But when I selecting the adjacent cell of the same edited row after editing, the entered value disappears.But When I selecting a cell other than the edited row  then Im able to get the changes as required.


Thank you in advance

6 Answers, 1 is accepted

Sort by
0
Accepted
Pavel Pavlov
Telerik team
answered on 17 Aug 2010, 12:04 PM
Hi josephine shirley,

I am attaching a small sample application which I believe resembles your scenario .
The relevant code is in the mainpage.xaml and mainpage.xaml.cs

*It is a Silverlight application , but exactly the same approach may be used in WPF as RadGridView for SL and RadGridView for WPF share a common API and codebase. If you find troubles with the project adn need it converted for WPF , just let me know.

In case this is not exactly what you are looking for , I will be glad to have a look at your code and check what is wrong.

Best wishes,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
josephine shirley
Top achievements
Rank 1
answered on 19 Aug 2010, 08:07 AM

Hi


Thanks for the reply.But my scenario is somewhat different from the one you've sent. PLease see the following

<telerikGrid:RadGridView x:Name="lstFieldDetails"   Grid.Row="1"   ShowGroupPanel="False"  SelectionMode="Single"   IsFilteringAllowed="False"  AutoGenerateColumns="false" CellEditEnded="lstFieldDetails_CellEditEnded">

                        <telerikGrid:RadGridView.Columns>

                                <telerikGrid:GridViewComboBoxColumn  IsComboBoxEditable="True" x:Name="cmbCategoryName" DataMemberBinding ="{Binding DBDCategoryID}" DisplayMemberPath = "Category Name" SelectedValueMemberPath = "Category ID" Header="Category Name"  />

                                <telerikGrid:GridViewDataColumn IsReadOnly="True"  IsEnabled="False"  x:Name="gvcDBDCategoryID" Width="Auto" IsVisible="false" Header="Category ID"  DataMemberBinding="{Binding DBDCategoryID}"/>

                                <telerikGrid:GridViewDataColumn  IsReadOnly="True"   IsEnabled="False"  x:Name="gvcFieldDescription" Width="Auto" Header="Field Description"  DataMemberBinding="{Binding FieldDescription}"/>

                            </telerikGrid:RadGridView.Columns>

  </telerikGrid:RadGridView>

    private void lstFieldDetails_CellEditEnded(object sender, Telerik.Windows.Controls.GridViewCellEditEndedEventArgs e)
        {


                string sCategoryName = ((Telerik.Windows.Controls.RadComboBox)e.EditingElement).Text;
 //updating db using new value
 //repopulating both the grid and combobox 
                string layerTableID = ((DataRowView)lstLayerDetails.SelectedItem)["LayerTableID"].ToString();
                if (!string.IsNullOrEmpty(layerTableID))
                {
                    DataTable dt;
                    dbParam = new DbParameter[1];
                    dbParam[0] = Trimble.UFS.Database.Helper.Parameter;
                    dbParam[0].ParameterName = "@LayerTableID";
                    dbParam[0].Value = layerTableID;
                    dt = new DataTable();
                    dt = Trimble.UFS.Database.Helper.ExecuteDT(_schemaName, "sp_ListAllFieldDetails", dbParam);
                    lstFieldDetails.ItemsSource = dt.DefaultView;
                    ///To repopulate the Comboboxcolumn

                    dt = new DataTable();
                    dt = Trimble.UFS.Database.Helper.ExecuteDT(_schemaName, "sp_ListAllCategoryIDs", null);
                    cmbCategoryName.ItemsSource = dt.DefaultView;
                }
            }

        }

The above scenario is very similar to the example given by the telerik documnetation (see following link).

http://www.telerik.com/help/wpf/radgridview-columns-column-types-combobox-column.html


We are having relationship between the radgridvew itemsource and the comboboxitem source.As per my requirement I need to have editing option for comboboxcolumn.In this case in the cell edit end event after changing the database I tried to repopulate both radgridview and combox altogether and leads to the following error.


After the event execution it leads to the following error:

{"Object reference not set to an instance of an object."}

 The related stack trace is as follows.



   at Telerik.Windows.Controls.GridView.GridViewCell.RaiseCellEditEndedEvent(GridViewEditAction editAction) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2\Sources\Development\Controls\GridView\GridView\GridView\Cells\GridViewCell.cs:line 910
   at Telerik.Windows.Controls.GridView.GridViewDataControl.PerformCellEditEnded(GridViewCell currentCell) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Editing.cs:line 98
   at Telerik.Windows.Controls.GridView.GridViewDataControl.CommitCellEdit(GridViewCell currentCell, Boolean isLeavingRow) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Editing.cs:line 65
   at Telerik.Windows.Controls.GridView.GridViewDataControl.OnCurrentCellInfoChanging(GridViewCellInfo oldCell, GridViewCellInfo newCell) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.cs:line 787
   at Telerik.Windows.Controls.GridView.GridViewDataControl.set_CurrentCellInfo(GridViewCellInfo value) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.cs:line 729
   at Telerik.Windows.Controls.GridView.GridViewDataControl.BeginEdit(GridViewCell gridViewCell, RoutedEventArgs editingEventArgs) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Editing.cs:line 467
   at Telerik.Windows.Controls.GridView.GridViewDataControl.BeginEdit(GridViewCell gridViewCell) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Editing.cs:line 462
   at Telerik.Windows.Controls.GridView.GridViewDataControl.OnCellMouseDown(GridViewCell cell) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Editing.cs:line 268
   at Telerik.Windows.Controls.GridView.GridViewCell.OnMouseLeftButtonDown(MouseButtonEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2\Sources\Development\Controls\GridView\GridView\GridView\Cells\GridViewCell.cs:line 383
   at System.Windows.UIElement.OnMouseLeftButtonDownThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at Shell.App.Main() in C:\Shire\Shire\Toolbox\Shell\obj\x86\Debug\App.g.cs:line 0

0
josephine shirley
Top achievements
Rank 1
answered on 25 Aug 2010, 07:00 AM
Can you let me know whether you able to replicate the error?
0
Pavel Pavlov
Telerik team
answered on 25 Aug 2010, 10:02 AM
Hello josephine shirley,

Can you please try execute the code which repopulates the grid and the column with Dispatcher.BeginInvoke() . In case this does not help we will look for another solution.


All the best,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
josephine shirley
Top achievements
Rank 1
answered on 31 Aug 2010, 10:43 AM
Ive used the Dispatcher.BeginInvoke() also.But it is not solving my problem.
0
Nedyalko Nikolov
Telerik team
answered on 03 Sep 2010, 12:52 PM
Hello josephine shirley,

Could you send me a sample project that simulates this issue, since I cannot reproduce the described error? After a detailed review of the stack trace I have a guess what could cause the null reference exception, unfortunately I cannot confirm that without a project.
Thank you in advance.

P.S. You have to open a separate support ticket in order to be able to attach a project. If you cannot open a support ticket send me a link to any public location.

Regards,
Nedyalko Nikolov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
josephine shirley
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
josephine shirley
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Share this question
or