Determine which Items are new when ProjectsEvents.ItemAdded is fired (VS Extensibility) - visual-studio

In my add-in I build List<> objects of specific file types (which are project items) during the Connect() event. In order to check and possibly append new items as and when these are added I've bound the relevant event:
ProjectsEvents.ItemAdded += ProjectsEvents_ItemAdded;
But the event only passes the Project which contains the new item, not the new item itself. So my question is, inside my ProjectsEvents_ItemAdded(Project proj) event, what's the best way to get this new item?
Do I have to iterate through all items in this project and determine whether I'm already aware of them?

Try ProjectItemsEvents.ItemAdded.

Related

Kendo ListView and MVVM 'edit template' cancel button resets bound data to initial state

I have a Kendo ListView bound to an Observable object and all is working well.
I'm able to:
Add items to the list
Edit existing items by using the edit template below
Delete items
One oddity though is when I switch an item to edit view and click Cancel it resets all data back to the original data. So if I started with one item with say name and amount fields, I edit the item and change the amount, then add two more items to the list all is well. But then I click edit on any of the items and immediately click cancel, from here it removes all the additional items I added and resets the data for the first item back to what it was at the beginning.
Why would the cancel action do that?
This dojo snippet shows the exact problem I'm having: http://dojo.telerik.com/IKowo
Kendo version 2016.3.1118
EDIT:
One further development, I found a forum post on Telerik stating that you have to have an ID column and a schema:model:id setup otherwise things won't work as expected.
I've updated the dojo snippet as follows: http://dojo.telerik.com/IKowo/2
Since adding the ID to the mix it looks like the amounts aren't being affected by the cancel button but the newly added items still get removed.
Follow the example provided here by telerik
//Binding Listview to local data array & Perform CRUD
http://dojo.telerik.com/eWih/2
The Only Requirement for the cancel event not deleting the new Items is:
The id field should be kept 0 when adding the new item to the datasource
It should be incremented / Updated in the datasource transport.create event (REQUIRED)
happy coding!

updating observable collection in windows phone 7 application

am developing a windows phone which contains database.I've a list box which binds observable collection to display the data retrieved from database. I am able to add and delete rows without any problem.After add or delete, listbox gets updated. But when i update a particular column, updating is working fine in database but in the display page i.e in listbox updated value is not reflected. To see the changes in database i need to relaunch the application.
Can any one tell me how to bind listbox at run time.
To reflect the changes of the properties, you need to implement the INotifyPropertyChanged interface in your data model class.So whenever the value of a property is changed you call the NotifyPropertyChanged() function, which will tell the binded UI Element to update its value.
The ObservableCollection just ensures that the binded listbox gets updated when an item gets added or deleted from it.
In order to see changes in a particular item, the item class must implement the INotifyPropertyChanged interface!

Adding a new item to ListBox.ItemsSource

I'm developing a Windows Phone app.
I have a listbox with this C# source code:
System.Collections.Generic.IEnumerable<OpenGame> items;
...
GamesList.ItemsSource = items;
If I want to add a new item (a new OpenGame object) to the GameList, how can I do it?
Use ObservableCollection rather than IEnumerable then you can use the Add method.
IEnumerable is for static lists where you don't want to add or remove members.
ObservableCollection is designed for lists bound to ListBoxes and similar controls. As well as allowing you to add and remove items it will notify the list box so it gets updated when the collection changes.
I think you can find you're answer with explanations in this thread:
How can I add an item to a IEnumerable<T> collection?

Windows DataGridView BindingSource Index out of range exception

Scenario:
Basically i have a
System.Windows.Forms.DataGridView
A class that inherits BindingSource and IBindingList
A class that has 2 standard List as private properties
DataGridView dgv = new ...
MyBindingSource bindingSource = new ...
MyList list = new ...
The DataGridView.DataSource property gets set to the BindingSource and the BindingSource.DataSource is set to one of the list's private List
bindingSource.DataSource = list.ListA;
dgv.DataSource = bindingSource;
I am getting a bunch of information streaming in from a database, and i convert the information to objects and add it to the MyList one at a time and in the end should be shown in the DataGridView.
I hope all that made sense, now the problem:
After adding a single object to the list (not the bindingsource) i want the item to be displayed in the DataGridView. But the only way i can currently get that to work is to construct another instance of a bindingSource with the 1 new object appended and set the DataGridView.DataSource to the new bindingSource. This ofcourse is horribly inefficient and the datagridview has to invalidate the whole thing every time, which is dodgy.
Instead i want the List to notifiy the BindingSource which tells the DataGridView a new object has been added so it can do it's thing. I tried this but i kept getting a IndexOutOfrange exception saying 'Item at index -1 does not have a value'.
I had a look at the BindingSource and indeed the position was -1 and the Current property threw that same exception. When i create the new BindingSource every time the position and Current properties are correct.
So what do i have to do in order for those properties to get updated when i add a item to the list? I opened it up with reflector to see where it was being set and looked like "CurrencyManager" had something to do with it. I tried a few things like base.OnDataMemberChanged base.OnListChanged to no avail.
Edit: Forgot to mention i only get the exception when i click on a row in the datagrid view, it adds the items fine. So it's like the DataGridView is out of sync with the BindingSource
When DataSource is changing its content, DataGridView clears its grid and raises SelectionChanged event and other events witch are connected with user interaction. It is iportant to know that when the event is raised there is no data at all to be displayed, so if u got a SelectionChanged event listener and it is accessing rows or columns inside, it will raise out of bound exception when accessing rows. Solution: always check Rows.count against 0 value before use any datagrid resources. Cheers
Have you considered using an ObservableCollection ? Whenever there are items added or removed from the collection it will notifiy the control its bound to that is has been updated. It will also do the same with properties of items in the collection as well ( although you have to raise the event manually )
I'm not to sure what could be causing the exception
If you use a BindingList(generic) instead it will notify of item adds/deletes and individual item changes as well. (http://msdn.microsoft.com/en-us/library/ms132679.aspx)

Communication between components (software design question)

I have an application with the following UI components:
Main Menu
Folders Tree
Query Builder
Tabbed Lists (each tab has a grid that can display data entities)
The application is based on MVC, so each component listed above has a controller and a view.
The first three components need to display data entities on the list (as new tabs):
Double clicking on a folder will display the folder's items in a new list.
When clicking the search button in the query builder it will open the search results in a new tab.
When clicking "Open..." menu item it and selecting a file it will open a new tab with the items in the file.
Since there could be a lot of items the process of loading them from the database is done asynchronously by the grid (the grid is being filled as you are looking at it).
My question is this: which of the following is a "cleaner" design? (if you have better solutions, I will appreciate it very much)
The first solution I have is to use an EventAggregator, define a "ShowQuery" event, make the lists controller subscribe to it, and the other controllers will publish it when they want to display the query results.
The other solution is something like the Unity Container, and from the other controllers resolve the "IListsController" interface, and call the "ShowQuery" method.

Resources