I know this because I put a breakpoint on the event handler and its not breaking as I add items to the collection.
Here's where I'm setting the event handler (in the USERCONTROL's Loaded handler:
this
.selectedAttributes.RowAdded += new EventHandler<Infragistics.Controls.Grids.RowEventArgs>(selectedAttributes_RowAdded);
Here's where I'm connecting the ObservableCollection to the XamGrid:
cvsSelectedAttributes.Source = vm.SelectedAttributes;selectedAttributes.ItemsSource = cvsSelectedAttributes.View;
In case its not obvious:vm.SelectedAttributes is an ObservableCollectioncvsSelectedAttributes is a CollectionViewSourceand selectedAttributes is a XamGrid
I've already tried removing the CollectionViewSource and connecting the ObservableCollection directly to the grid, like so:
selectedAttributes.ItemsSource = vm.SelectedAttributes;
It didn't help.
Here's the event handler:
void selectedAttributes_RowAdded(object sender,Infragistics.Controls.Grids.RowEventArgs e){ SelectedAttributes dataGrid = (SelectedAttributes)sender;
if (dataGrid != null) { dataGrid.ScrollCellIntoView(e.Row.Cells[0]); }}
The items are appearing as new rows in the XamGrid. Why on earth is this event not being fired? Am I missing a property setting or something else?
Pleas help ASAP!
Hi,
I have been looking into your enquiry and this is the designed behavior as the RowAdded event is not meant for detecting, whether items are added to your underlying collections. The event is meant to go off when you add a new row through the XamGrid’s UI: http://samples.infragistics.com/sllob/RunSamples.aspx?cn=grid#/grid/add-new-row . This is because, only in our designed environment we can provide consistent behavior, unlike all the types of collections arrays and tables that can provided as ItemsSource. In order to register the changes to your collection you can use its built-in functionality e.g. for the ObservableCollection, since it implements INotifyCollectionChanged, you can register for its CollecitonsChanged event.
Please let me know if you require any further clarification on the matter.
Hi Petar,
I find it hard to believe and accept your response. One reason is that the row is actually being added to the XamGrid as I can visually see it in the grid. If you can sense the fact that I've added a row to the collection and consequently you add the row to the grid, what's so difficult about firing the 'RowAdded' event? (I am quiet familiar with the ObservableCollection's INotifyCollectionChanged interface and the CollectionChanged event). To me, if a row is added then the RowAdded event should fire, period.
Now, let's suppose I put some code in the CollectionChanged event handler, from this event how am I supposed to get a reference to the XamGrid Row that is being added? I need a reference to the XamGrid row added in order to scroll the row into view:
ScrollCellIntoView(e.Row.Cells[0])
I need help ASAP.
Thanks,
Joe
Hi Joe,
I see what you mean, however the intent of the event itself is to accommodate and register adding records through the XamGrid’s UI. Any actions that are triggered and can be handled through code are not supposed to trigger events in order to optimize performance and because as developers we can correspond to them with code. Regarding your particular question, I gave it quite some though in order to come up with a few approaches, however I am particularly happy with the last one. In the observable collection’s CollectionChanged event I used the Dispatcher’s BeginInvoke method, to make sure the body of the underlying function is executed after the item that is being added at that moment, has time to make it to the XamGrid and be present there when I set it to the XamGrid’s ActiveItem property. This in turn automatically sets the corresponding Row’s first Cell as Active cell and we are able to use the ScrollCellIntoView. Here is a code snippet for the above:
void people_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
Dispatcher.BeginInvoke(new Action(() =>
xamGrid1.ActiveItem = e.NewItems[0];
xamGrid1.ScrollCellIntoView(xamGrid1.ActiveCell);
}), null);
}
Please let me know if I can be of any further assistance on the matter.
That works.
I am still disappointed that the RowAdded event only works from the UI!
At the very least, the documentation should be updated to note (with emphasis) this limitation. Had the documentation alerted me to this, it would have saved many hours of frustration.
Thank you for your assistance,
I am really glad to hear this solves your issue. Regarding the documentation, there is no emphasis, since most events work in such a manner.
If the behavior is otherwise there is a solid reason for that, however if you think of it not firing most of the numerous events from coded actions, does have its effect on performance and know that your code should trigger any follow up action does allow you to react accordingly on your own.
Hope this clarifies things.
>> Regarding the documentation, there is no emphasis, since most events work in such a manner.
Is it stated someplace in the documentation, that I have overlooked, that most events behave in the manner you describe? If so, I'd appreciate if you would point me to it.
Even though I have gone through it countless times, I have not encountered such a statement in the documentation.
Please let me know if I can be of any further assistance on this matter.