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!
Related
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!
Let me explain the my scenario. I am using ExtJS5. I have got a view component (let us name is viewOne) contain two combo boxes, button search and some action button, on click of search button the grid is populated. This viewOne is in a parent view component (viewParent). I need to load a second view (viewTwo) on selecting some grid row and clicking some action button a new view is loaded (viewTwo) in the parentView. When I come back from viewTwo to viewOne I need old values of combo boxes to re perform the search.
Currently I am storing the values of combo boxes in a store and set then when the after view render and call search. We have discarded card layout for this implementation.
I wanted to know how this can be done via Ext.state , I cannot find any example on the same that is close solution to my problem. Any other way of doing this ?
State seems reasonable for that. First of all you must set StateProvider (by calling Ext.state.Manager.setProvider) to instance of class which extends Ext.state.Provider.
Then state should work for you. Only thing that you must remember is to set stateful property to true and set stateId of the component.
Usually you don't need to save state by yourself. All built-in stateful components have defined state events. When such state event occur (eg. expand on panel) then state is saved automatically. You can customize state events by calling addStateEvents in initComponent.
To provide custom component state you should override applyState and getState methods. When you combine it with addStateEvents you have all what you need.
Example: http://jsfiddle.net/48jw81da/16/
I have a view with a list box, bound to am obvervable collection of DisplayItems, which has 'Label', 'DisplayValue' and 'IconUri' properties.
I have a View Model which exposes this observable collection. The List Box is correctly populated first time around.
I then have a button which takes action on the selected item. I need to indicate that action has been taken by changing the image.
I am changing the IconUri of the selected item, and can see the new value present when debugging, but the image doesn't change. I can also change the 'Label' and 'DisplayValue' properties and see the new values correctly there when debugging, but the list doesn't change.
My ViewModel implements INotifyPropertyChanged. My DisplayItem class implements INotifyPropertyChanged. I'm calling RaisePropertyChanged I'm sure in too many places rather than too few.
None of the changes are ever reflected on screen.
I'm using a DataItemTemplate for the generated rows. If I could access the image of the selected row I could change it manually, but I can't even do that.
Any help greatly appreciated. I could actually do with a example of a list box displaying items from a bound observable collection, where one property of the selected item is changed and that change is reflected in the list box.
Thanks in advance
A
You didn't implement INotifyPropertyChanged correctly, or you're using it wrong.
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)
I haven't been able to successfully bind some test data to a SketchFlow ComboBox. I added a sample data source and created a collection with some basic string values. There are a number of tutorials on how to bind to a ListBox in SketchFlow and that works fine, just not finding anything for a ComboBox.
One thing that caught me out a few times is that you need to have your data in "list mode" before you drag it on to the control (combo box or list box).
It seems to work as I expected, so perhaps I'm not understanding your issue correctly, but I'll give it a shot! I created a sample DataSource with a couple of strings in it, added a ComboBox to the layout root and then just dragged the Collection from the DataSource and dropped it on the ComboBox.
Keep in mind that if you drag the DataSource itself, you'll only be setting the DataContext property of the ComboBox and that's not enough to get your items to display. You also need the ItemsSource bound to the Collection of the DataSource and an ItemTemplate or a DisplayMemberPath to tell the ComboBox how to display your items.
Additionally, if you use the drag and drop method of binding, it will use the ItemTemplate approach for you, which may or may not be what you want as it will generally create a StackPanel and display all fields from the row in your Collection per item in the ComboBox. You can remove the ItemTemplate and set DisplayMemberPath to whichever field you wish to have displayed from your data source's collection.