Silverlight Application throwing Null reference Exception on clearing list which is bound to Grid - silverlight

In Silverlight Application I have bound one ObservableCollection to Grid.
But when I edit row of grid,I am saving updated data in db and clear observable collection of grid and reinsert new values in it.
but when I try to clear observable collection it is throwing an error "Object reference not set to an instance of an object"
Am I missing Anything here.
Code:
MyList.Clear();
StackTrace of Exception
at
Infragistics.AutomationPeers.CellsPanelAutomationPeer.Row_PropertyChanged(Object
sender, PropertyChangedEventArgs e)\r\n at
System.ComponentModel.PropertyChangedEventHandler.Invoke(Object
sender, PropertyChangedEventArgs e)\r\n at
Infragistics.RecyclingContainer1.OnPropertyChanged(String name)\r\n
at Infragistics.Controls.Grids.Row.SetSelected(Boolean isSelected)\r\n
at
Infragistics.Controls.Grids.Row.Infragistics.ISelectableObject.SetSelected(Boolean
isSelected)\r\n at
Infragistics.Controls.Grids.SelectedCollectionBase1.InternalRemoveItemSilently(Int32
index)\r\n at
Infragistics.Controls.Grids.SelectedCollectionBase1.RemoveItem(Int32
index)\r\n at Infragistics.Collections.CollectionBase1.Remove(T
item)\r\n at
Infragistics.Controls.Grids.RowsManager.InvalidateSelectionAndActivation(Boolean
validateInList, Boolean invalidateSelection)\r\n at
Infragistics.Controls.Grids.RowsManager.InvalidateItemSource(Boolean
invalidateSelection)\r\n at
Infragistics.Controls.Grids.RowsManager.DataManager_CollectionChanged(Object
sender, NotifyCollectionChangedEventArgs e)\r\n at
Infragistics.DataManagerBase.OnCollectionChanged(NotifyCollectionChangedEventArgs
e)\r\n at
Infragistics.DataManagerBase.OnDataSourceCollectionChanged(NotifyCollectionChangedEventArgs
e)\r\n at
Infragistics.DataManager1.OnDataSourceCollectionChanged(NotifyCollectionChangedEventArgs
e)\r\n at
Infragistics.DataManagerBase.DataSource_CollectionChanged(Object
sender, NotifyCollectionChangedEventArgs e)\r\n at
System.Collections.ObjectModel.ObservableCollection1.OnCollectionChanged(NotifyCollectionChangedEventArgs
e)\r\n at
System.Collections.ObjectModel.ObservableCollection1.ClearItems()\r\n
at System.Collections.ObjectModel.Collection1.Clear()\r\n at

Related

Routed event handlers drag drop information

If I register a class handler like so:
EventManager.RegisterClassHandler(
typeof(ListBoxItem),
DropEvent,
new RoutedEventHandler(OnListBoxItemDropEvent));
The following method signature is expected:
private void OnListBoxItemDropEvent(object sender, RoutedEventArgs e)
The standard Drop method signature is the following:
private void Drop(object sender, DragEventArgs e)
i.e. it gives you access to the DragEventArgs e
Is there a way for me to access the DragEventArgs e when registering a routed event handler?
How about creating a DragEventHandler (instead of a RoutedEventHandler)?:
EventManager.RegisterClassHandler(
typeof(ListBoxItem),
DropEvent,
new DragEventHandler(Drop));

WPF XAML error "Cannot be null parameter name root"

In Visual Studio 2015, I am trying to create a XAML control from an existing base class in my project, but I'm getting the error shown below. What's wrong?
error screenshot
Here's a bit more information:
at Ninject.ResolutionExtensions.GetResolutionIterator(IResolutionRoot root, Type service, Func`2 constraint, IEnumerable`1 parameters, Boolean isOptional, Boolean isUnique)
at Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] parameters)
at Render.Core.Models.ModelBase.get_Project()
at Render.Core.Models.ModelBase.get_Interface()
at Render.Core.Models.StaticModelBase.get_Interface()
at Render.Core.RenderControls.RenderHeader..ctor(String title, ContentControl image, Boolean isAdminHome)
at Render.MainApplication.Views.Shared.ViewBase.CalcSize()
at Render.MainApplication.Views.Shared.ViewBase.ViewBase_SizeChanged(Object sender, SizeChangedEventArgs e)
at System.Windows.SizeChangedEventArgs.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 System.Windows.FrameworkElement.OnRenderSizeChanged(SizeChangedInfo sizeInfo)
at System.Windows.ContextLayoutManager.fireSizeChangedEvents()
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.UIElement.UpdateLayout()
Apparently the problem is related to Ninject. Maybe I need to include some kind of namespace declaration for that?

Retrieving the state(checked/unchecked) of a checkbox column in datagridview in ADO.NET

I have added a DataGridViewCheckBoxColumn in a datagridview and want to commit changes in database on checking and unchecking this checkboxcolumn. Please assist.
Thanks.
try this:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
Debug.WriteLine(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
}
in CellValueChanged Event you can retrieve the changed value only if you called CommitEdit before ...

A NullReferenceException exception in System.Windows.Forms.DataGridView

I have a .NET 4.0 WinForms application. A Form of the application contains a Grid – an System.Windows.Forms.DataGridView object
Suddenly I have got a (non-reproducible!) NullReferenceException in it. The call stack was the following:
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Forms.DataGridView.UnwireEditingControlEvents()
at System.Windows.Forms.DataGridView.EndEdit(DataGridViewDataErrorContexts context, DataGridViewValidateCellInternal validateCell, Boolean fireCellLeave, Boolean fireCellEnter, Boolean fireRowLeave, Boolean fireRowEnter, Boolean fireLeave, Boolean keepFocus, Boolean resetCurrentCell, Boolean resetAnchorCell)
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
at System.Windows.Forms.DataGridView.set_CurrentCell(DataGridViewCell value)
at System.Windows.Forms.DataGridView.OnClearingRows()
at System.Windows.Forms.DataGridViewRowCollection.ClearInternal(Boolean recreateNewRow)
at System.Windows.Forms.DataGridView.RefreshRows(Boolean scrollIntoView)
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs e)
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged(Object sender, ListChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
at System.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e)
at System.Windows.Forms.BindingSource.InnerList_ListChanged(Object sender, ListChangedEventArgs e)
at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
at System.ComponentModel.BindingList`1.FireListChanged(ListChangedType type, Int32 index)
at System.ComponentModel.BindingList`1.ClearItems()
at System.Collections.ObjectModel.Collection`1.Clear()
at <My Code>;
The calls method Clear of a BindingList-derived list. The BindingList-derived list is, in turn, used in a BindingSource object. The BindingSource object is a datasource of the DataGridView.
I cannot understand – why this happens? And why it happens only sometimes? (to the moment I have seen the problem only once).
And how can this be avoided?
Ran into this myself just now. In my case, I noticed it only happens if the grid has more than about 10 rows or so and you immediately try to go to the last row. My workaround was, after setting the BindingSource, to manually set the current cell to a cell within the first row:
grdConditions.DataSource = myDataSource;
if (grdConditions.Rows.Count > 0)
grdConditions.CurrentCell = grdConditions[0, grdConditions.RowCount - 1];
Seemed to fix the issue for me.

WPF : How to get mouse position in Window_Loaded(object sender, RoutedEventArgs e) event

WPF : How to get mouse position in Window_Loaded(object sender, RoutedEventArgs e) event
Have you tried using PointToScreen(Mouse.GetPosition(this)) ?
(in the System.Windows.Input namespace)

Resources