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

CurrentRecord.Fields doesn't work anymore

6 Answers 155 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 06 Nov 2008, 08:12 PM
I have this property:

 public int SelectedRecordID 
        { 
            get 
            { 
               if (gvSearchResults.ItemsSource != null) 
                   return Convert.ToInt32(gvSearchResults.CurrentRecord.Fields[0].Value); 
                else 
                    return 0; 
            } 
        } 

it no longer works after upgrading to your Nov 5 release.  .Fields is not recognized.  How can I fix?

Thanks,
Scott

6 Answers, 1 is accepted

Sort by
0
Atanas
Telerik team
answered on 07 Nov 2008, 01:24 PM
Hi Scott,

Actually the idea of the functionality you are asking for is a little different now. The CurrentRecord property of RadGridView control is of DataRecord type. To get the underlying business object, a simple cast is needed:

DataRecord currentRecord = (DataRecord) gvSearchResults.CurrentRecord; 

The DataRecord class has a property Data of object type, which is the business object the record is binded to.

After this, all you need to do is one last cast - the Data property to the type of your business object and directly to operate with the properties of the object. The code should look like this:

MyType myObject = (MyType) currentRecord.Data;  

Maybe this approach is not quite straightforward, but this is the way we handle it right now
.
Thank you for your understanding and your patience.


Regards,
Atanas
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mike
Top achievements
Rank 2
answered on 18 Mar 2009, 07:06 PM
In Q1 2009 DataRecord does NOT have a data property.

So...  How do I get to the data of the current selected item via code in Q1 2009?

---------------------

Telerik.Windows.Data.Record dr = gvwResults.CurrentRecord;


dr does not have a data property.  I do a watch on dr I can see a data property and my data, but I can't access it via the DataRecord.

~Mike
0
Vlad
Telerik team
answered on 19 Mar 2009, 10:50 AM
Hello Mike,

You need to cast to DataRecord.

Kind regards,
Vlad
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mike
Top achievements
Rank 2
answered on 19 Mar 2009, 01:18 PM
Hi Vlad,

You're totally right, I casted this incorrectly, and saw that after I posted - sorry.  But...  I still have an issue.

I am using Linq2SQL to bind the WPFGridView.

Data.dbGSV1DataContext dbGS = new GS_Sys_Admin_V1_1.Data.dbGSV1DataContext(); 

ds = from mat in dbGS.MarketingAccountTypes  
     join st in dbGS.StatusTypes on new { StatusTypeID = Convert.ToInt32 (mat.StatusTypeID) } equals new { StatusTypeID = st.StatusTypeID } into st_join  
     from st in st_join.DefaultIfEmpty()  
     select new stuff  
     {  
         ID = mat.MrkAccTypeID,  
         TypeName = mat.MrkAccTypeName,  
         StatusID = mat.StatusTypeID,  
         CreatedBy = mat.CreatedBy,  
         CreatedDate = mat.CreatedDate,  
         ModifiedBy = mat.ModBy,  
         ModifiedDate = mat.ModDate,  
         StatusTypeName = st.StatusTypeName  
     }; 

gvwResults.ItemsSource = ds;  
gvwResults.ColumnsWidthMode = Telerik.Windows.Controls.ColumnsWidthMode.Fill; 

The grid fills fine.  As you can see I am selecting my results into an object called stuff.

public class stuff  
{  
    public int ID { getset; }  
    public string TypeName { getset; }  
    public int? StatusID { getset; }  
    public int? CreatedBy { getset; }  
    public DateTime? CreatedDate { getset; }  
    public int? ModifiedBy { getset; }  
    public DateTime? ModifiedDate { getset; }  
    public string StatusTypeName { getset; }  

On the SelectionChanged event I am trying to get the data but having issues.

private void gvwResults_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)  
        {  
            Telerik.Windows.Data.DataRecord dr3 = (Telerik.Windows.Data.DataRecord)gvwResults.CurrentRecord;  
            stuff mystuff = (stuff)dr3.Data;  
        } 

The code blows up on casting the data into a stuff object.

Now, dr3 does have data - see below.

Immediate Window
-----------------------------------------------

dr3.Data

{ ID = 2, TypeName = "Forum", StatusID = 1, CreatedBy = 0, CreatedDate = {3/18/2009 11:09:00 AM}, ModifiedBy = 0, ModifiedDate = {3/18/2009 11:09:00 AM}, StatusTypeName = "Active" }

CreatedBy: 0

CreatedDate: {3/18/2009 11:09:00 AM}

ID: 2

ModifiedBy: 0

ModifiedDate: {3/18/2009 11:09:00 AM}

StatusID: 1

StatusTypeName: "Active"

TypeName: "Forum"

But on trying to cast as stuff I get the following error: "There is no source code available for the current location."

Here is the Disassembly:
--------------------------------------------

 

00000028 mov edx,1

0000002d cmp dword ptr [ecx],ecx

0000002f call 4B517308

00000034 mov eax,dword ptr [ebp-4]

00000037 mov dword ptr [ebp-0Ch],eax

0000003a mov edx,dword ptr [ebp-4]

0000003d mov ecx,dword ptr [ebp-8]

00000040 call FFFC95B0

00000045 mov dword ptr [ebp-10h],eax

00000048 mov edx,dword ptr [ebp-10h]

0000004b mov ecx,dword ptr [ebp-0Ch]

0000004e call dword ptr ds:[05187304h]

00000054 nop - LINE ERROR IS HERE

00000055 mov esp,ebp

00000057 pop ebp

00000058 ret

 

 

---------------------------------------------

After clicking to see the Disassembly is see the follow error:
{"Exception has been thrown by the target of an invocation."}
The InnerException is:
{"Unable to cast object of type '<>f__AnonymousType4`8[System.Int32,System.String,System.Nullable`1[System.Int32],System.Nullable`1[System.Int32],System.Nullable`1[System.DateTime],System.Nullable`1[System.Int32],System.Nullable`1[System.DateTime],System.String]' to type 'GS_Sys_Admin_V1_1.UserControls.Marketing.stuff'."}


Here is the full exception:
-------------------------------------------------------
System.Reflection.TargetInvocationException was unhandled
  Message="Exception has been thrown by the target of an invocation."
  Source="mscorlib"
  StackTrace:
       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.Windows.RoutedEventArgs.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.RaiseEvent(RoutedEventArgs e)
       at Telerik.Windows.Controls.RadRowItem.HandleMouseLeftButtonDown(RowItemMouseEventArgs args) in c:\Builds\WPF_Scrum\Charting_CI_Build\Sources\Development\WPF\Data\RadRowItem.cs:line 296
       at Telerik.Windows.Controls.RadRowItem.OnMouseLeftButtonDown(MouseButtonEventArgs e) in c:\Builds\WPF_Scrum\Charting_CI_Build\Sources\Development\WPF\Data\RadRowItem.cs:line 287
       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.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender, MouseButtonEventArgs e)
       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.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, Int32 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, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       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 GS_Sys_Admin_V1_1.App.Main() in C:\Projects\WPF\GS_Sys_Admin_V1_1\GS_Sys_Admin_V1_1\obj\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.InvalidCastException
       Message="Unable to cast object of type '<>f__AnonymousType4`8[System.Int32,System.String,System.Nullable`1[System.Int32],System.Nullable`1[System.Int32],System.Nullable`1[System.DateTime],System.Nullable`1[System.Int32],System.Nullable`1[System.DateTime],System.String]' to type 'GS_Sys_Admin_V1_1.UserControls.Marketing.stuff'."
       Source="GS_Sys_Admin_V1_1"
       StackTrace:
            at GS_Sys_Admin_V1_1.UserControls.Marketing.ucMrkAccTypes.gvwResults_SelectionChanged(Object sender, SelectionChangeEventArgs e) in C:\Projects\WPF\GS_Sys_Admin_V1_1\GS_Sys_Admin_V1_1\UserControls\Marketing\ucMrkAccTypes.xaml.cs:line 227
            at Telerik.Windows.Controls.DataControl.RaiseSelectionChangedEvent(SelectionChangeEventArgs args) in c:\Builds\WPF_Scrum\Charting_CI_Build\Sources\Development\WPF\Data\DataControl.cs:line 478
            at Telerik.Windows.Controls.GridView.GridViewDataControl.RaiseSelectionChangedEvent(SelectionChangeEventArgs args) in c:\Builds\WPF_Scrum\WPF_Team\Sources\Development\WPF\GridView\GridView\GridViewDataControl.cs:line 1622
            at Telerik.Windows.Controls.DataControl.RaiseSelectionChangedEvent(IList`1 addedRecords, IList`1 removedRecords) in c:\Builds\WPF_Scrum\Charting_CI_Build\Sources\Development\WPF\Data\DataControl.cs:line 467
            at Telerik.Windows.Data.Selection.SelectionHandler.RaiseSelectionChanged(List`1 addedRecords, List`1 removedRecords) in c:\Builds\WPF_Scrum\Charting_CI_Build\Sources\Development\WPF\Data\Selection\SelectionHandler.cs:line 439
            at Telerik.Windows.Data.Selection.SelectionHandler.EndSelection() in c:\Builds\WPF_Scrum\Charting_CI_Build\Sources\Development\WPF\Data\Selection\SelectionHandler.cs:line 332
            at Telerik.Windows.Data.Selection.SelectionHandler.PerformSelection(Record record, ModifierKeys modifierKeys) in c:\Builds\WPF_Scrum\Charting_CI_Build\Sources\Development\WPF\Data\Selection\SelectionHandler.cs:line 169
            at Telerik.Windows.Controls.SelectionManager.RadRowItem_RowMouseDown(Object sender, RowItemMouseEventArgs e) in c:\Builds\WPF_Scrum\Charting_CI_Build\Sources\Development\WPF\Data\SelectionManager.cs:line 153
       InnerException:
-------------------------------------------------------

So...  Where am I going wrong.

~Mike

0
Mike
Top achievements
Rank 2
answered on 23 Mar 2009, 07:11 PM
Any response on this Telerik?

~Mike
0
Vlad
Telerik team
answered on 24 Mar 2009, 07:13 AM
Hello Mike,

I tried to reproduce such error to no avail - please check attached project for more info.

Can you send us small running demo where we can reproduce this exception?

Sincerely yours,
Vlad
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Scott
Top achievements
Rank 1
Answers by
Atanas
Telerik team
Mike
Top achievements
Rank 2
Vlad
Telerik team
Share this question
or