Hello,
I have a XamDataGrid that binds to an object that have only a private constructor. So I had to create my own add new record button. Since I over wrote the add button already implemented in grid, I'm not getting focus on the new record.
1) How can I put the focus on the new added record. Please note that I'm using MVVM pattern.
2) I have set AddNewRecordLocation="OnTop" but the record is getting added on the button.
I'm wondering if someone looking into my question.
Thank you
Can you send a small sample project demonstrating the issue you are having? It's unclear exactly what the issue is. If all you want is to set to activate the first record in the grid you can set the IsActive property on the record.
this.xamDataGrid1.Records[0].IsActive = true;
The attached sample project throws an exception when the Add button is clicked.
Did you test the solution ?
Yes I have.
No exception occurs when I click the add button. Please provide more details on the exception and clarify how to reproduce it and explain whether or not if this is occurring within your app or the sample. If the sample isn't working, which version of Infragistics are you using specifically? I'll need the four digit build number found in the details of the assemblies.
Let me know if you have any questions.
Hello Michael,
Exception is occurring in the sample project. The version is 16.1.20161.100.
Exception Details:
System.NullReferenceException was unhandled HResult=-2147467261 Message=Object reference not set to an instance of an object. Source=xamDataGridSample StackTrace: at xamDataGridSample.MainWindow.<>c__DisplayClass1_0.<ECollection_CollectionChanged>b__0() in C:\Users\harbali\Desktop\xamDataGridSample\xamDataGridSample\xamDataGridSample\MainWindow.xaml.cs:line 50 at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) 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 MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(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 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(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.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at xamDataGridSample.App.Main() in C:\Users\harbali\Desktop\xamDataGridSample\xamDataGridSample\xamDataGridSample\obj\Debug\App.g.cs:line 0 at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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.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.Threading.ThreadHelper.ThreadStart() InnerException:
Thanks for providing more details. Which line in the sample does this issue occur?
Please note that the only way I can reproduce this exception is if I scroll the ‘addnew’ row out of view and click the button. The cell(s) needs to be in view to be in edit mode. (The exception does not occur in the sample if you immediately click the button without any additional steps taken)
To work around this you’ll need to set the vertical offset of the ScrollInfo member of the grid and perform a layout update, so the add new row is brought into view first.
Eg.
xamDataGrid1.ScrollInfo.SetVerticalOffset(0);xamDataGrid1.UpdateLayout();
I’ve modified your sample and uploaded here.
Hey Michael,
I have tested around the sample project.
I was to add rows to the button of the grid, it will hit the exception once the row goes out of view.
Increasing the SertVerticalOffSet(100) did the job.
Thank you for you hard work on this issue.
I hope other users can benefit from this lengthy chain of posts.