ListBox not updating - c#

I am using a ListBox in one of the windows form application. When the screen first initializes, I am able to add/remove item into the listbox. However, after I click on one of the buttons to change the content of the listbox, the listbox does not update the values. I tried putting the Listbox inside a Panel and Refreshing the panel to no avail. Anyone ran into same problem?

It sounds as though the data source you are binding to does not support IBindingList.

Related

Accommodate custom item on winrt listview

I'm developing windows metro app. In my application, I've one Listview with wrapgrid in itemspanel to display list of items on vertical rows with specific height. I want to display one item on top of the first column of list view, which shows result/stats of list items.
I would like to know if it is possible without adding custom item to datasource of listview?
ListView has a Header property in which you can Place content before the ListViews Items.
As commented, I've implemented following solution which is not elegant but worked for me.
Use Datasource converter to add dummy item in main list. So, my original list remains as is.
Use Template Selector to bind different template for first item.
Handle Selection and clicked event of dummy item.

Not showing items with Visibility=Collapsed in Windows 8.1 GridView

I have a Windows 8.1 application with a GridView bound to a custom (sortable, deduplicated) observable collection. In this collection, I do some heavy filtering and setting an IsHidden flag for every item.
In the data template for the item, there is a condition making the item collapsed if IsHidden flag is set to true.
<Grid Width="160" Height="280" Visibility="{Binding IsHidden, Converter={StaticResource InvertedBooleanToVisibilityConverter}}">
This approach works in Windows Phone 8.1 XAML, making the items disappear from the ListView but it does not work in Windows 8.1 GridView. The problem with Windows 8.1 is that when I set an item in the collection to hidden, id disappears from the GridView but leaves an empty place, so there is a gap in the GridView.
Any ideas on how to solve it? Maybe same XAML style editing?
Here is a minimal solution to reproduce the problem: https://dl.dropboxusercontent.com/u/73642/gv.zip
I tried binding width and height of the items to the hidden flag and setting it to 0 when the item is hidden, but it did not help, still a gap in the GridView.
Update: One workaround would be filtering the actual bound collection, but this is not possible, because of some business requirements.
The problem is in the GridView's ItemsPanel.
Both ItemsWrapGrid and WrapGrid are uniform grids. All their child elements will be sharing the same height and width. That's why even if you collapse the ItemTemplate, the space is still reserved.
What you really need here is a WrapPanel. WINRT doesn't have a built-in WrapPanel but Jerry Nixon has built one and you can grab it from here.
After you updated your GridViews ItemsPanel, you still have one more thing to do. You need to also get the GridViewItem that hosts your Itemtemplate and set its Visibility to Collapsed.
private async void Button_Click(object sender, RoutedEventArgs e)
{
ds[5].IsHidden = true;
await Task.Delay(1000);
var gridViewItem =(GridViewItem)this.gv.ContainerFromIndex(5);
gridViewItem.Visibility = Visibility.Collapsed;
}
I put a little delay above to make the collapsing more obvious.
I tried your sample solution and changed it to a ListView instead. It exhibits the same behavior when the grid itself is hidden. I don't have XAML Spy to verify, but it appears that any List based control will allocate a rendered item for each item in the list.
I changed your click handlder to instead ds.RemoveAt(5); instead of hiding the item, and the element is removed from view with a nice animation. This appears to be as expected, and an interesting find.
It takes me a lot of time to understand the problem, and the solution right in front of my eyes. You trying to hide the item itself but the container still there, When you add an item to an GridView, the item is wrapped in an item container. from msdn :
" When you add an item to an ItemsControl, the item is wrapped in an
item container. For example, an item added to a ListView is wrapped in
a ListViewItem. Without UI virtualization, the entire data set is kept
in memory and an item container is also created for each item in the
data set. A ListView that's bound to a collection of 1000 items will
also create 1000 ListViewItem containers that are stored in memory."
You need to disable the container and create two DataTemplate and using DataTemplateSelector you can choose which DataTemplate for disable and active items. Check this useful article .

WP7 Panorama items binding and adding other custom panorama items c#

I am running into an issue where i am using a panorama control and binding it to a datasource. But i still do want other custom items on another panorama items where i need a textblock, a grid and so on. So if i am adding it in the backend it doesnt show up those panorama items. It just shows the datasource binded items. Why is that so? Both of them should work out.
Can anybody help me with a solution for this.
Thank You.
Since you're wanting to manually add PanoramaItems, I can think of two approaches:
Make sure your Panorama.ItemsSource is set to an ObservableCollection that is accessible in the code behind or viewmodel, and then add your new items to that ObservableCollection which should update the Panorama.
Don't databind the Panorama control's Items - just add items manually when you want them.
Either way, the Panorama's ItemTemplate gets evaluated when the items are added to the underlying collection, so using a DataTemplateSelector will allow your code to determine which DataTemplate to apply when the new item is added without affecting the templates for previous items.
/chris

How to reload data into image listbox itemtemplate? Takes to long

I have three Buttons options that retrieve data from db and sets datacontext to ListBox, since I added an image to the ListBox ItemTemplate each time I click a different menu option, takes way to long to refresh items. Images are between 15KB and 45KB, and loaded locally. Already tried, VirtualizingStackpanel="Recycling" didn't work, maybe I missed something.
How many items are there in your listbox ? Do you have any grouping in your listbox ?
If not then you may have to look at the datavirtualizaton in wpf.Please check the links below for more
http://bea.stollnitz.com/blog/?p=338
http://social.msdn.microsoft.com/Forums/en/wpf/thread/98090161-0abf-4799-bbcb-852dcc0f0608
Did you change the default ItemsPanel to a VirtualizingStackPanel?

Winform ListView databind

I have a Listview that uses databind. I set the DataSource property to a binding source. All works fine. The problem is that I need to have a column that is not databinded and contains only buttons that have the same handler for click event. To accomplish this I tried to add a subitem that is a button for each ListViewItem after InitializeComponent but doesn't work, nothing is displayed. Also I set the list view column type to Control.
If I add elements to ListView and isn't databinded that the buttons appear.
So it will be a great help for me to know if buttons could be displayed in column that is not databinded when the listview uses databinding for rest of columns.
Thanks!
The best thing to do here (assuming you mean ListBox), is to have a single button above or below the listbox, that uses the ListBox.SelectedItem property to investigate the selected item and do something with it.

Categories