Scrolling ListView with mouse wheel occasionally negates scroll - c#

I'm having some trouble with the Win32 listview, and I hope someone has some wisdom. When scrolling very quickly (via the wheel), occasionally, the listview appears to scroll, only to jump back to the selected item so it is in-view. In other words, the list undoes your wheel scroll to show you the selected item at the top/bottom of the list. I realize this sounds very dubious, as the common controls have been beaten to death the world over.
Here's how you can replicate:
Load up a listview in report mode with about 500 items or so (exact count doesn't matter, you just want several screens of data).
Select an item in the list and remember what you selected.
Rapidly scroll the list with the wheel downwards (toward you). We're trying to scroll the selected item out of view as fast as possible. You probably have to use more force than you usually use on the wheel. This won't always happen. You may have to try several times.
Either the scroll will complete normally, or it will change its mind at the end and pull you back to a view where the selected item is on the screen.
This happens with both regular and virtual listviews. I've tested Win32 and C# on Windows 7 Ultimate.
I made a small WinForms app that exhibits the behavior (requires .NET Framework 3.5). If you'd rather not run arbitrary executables from strangers (I understand), make a new WinForms app, drop a listview in report mode in, add a column, and populate the list in the form load event with 500 increasing integers:
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 500; i++)
{
this.listView1.Items.Add(i.ToString());
}
}

I've noticed this behavior and it does seem to be built into the list view control. I can't see any reason why the functionality would be useful. I created a thread on this at Sysinternals Forums a while back. It might be useful.

"I realize this sounds very dubious, as the common controls have been beaten to death the world over."
ListView hasn't quite been beaten to death but it's on life support. Use a different control.

is it a custom list view (overriding drawing ?)
by the way, I faced (from what I understand) the same issue with a custom Listbox and found some help here :
http://aviationxchange.net/wikis/winforms/net-color-listbox.aspx (end of the document).
Hope this could help.

I was facing the same problem but I think I found the cause: I use a tool that allows you to configure the mouse buttons (X-Mouse Button Control). By disabling it, the problem disappeared like magic.

Related

Why UWP Flipview doesn't flip to second item?

I have a control to manage a FlipView (flipView) and I want synchronize SelectedIndex with a ListBox (subMenuList) to navigate between my contents. And because product owners have wonderfull requirements, I have another ListBox (shortcutList) in a control for the first item of the FlipView which is also binded to SelectedIndex of the FlipView.
Warning : some items of the lists are collapsed to simulate shortcuts to Flipview contents.
Those controls are perfectly synchronized together but the second item of FlipView :
Using mouse: on the first click, I can go to page 1 and when I flip back to shortcutList, I can not go to page 1 but I can go anywhere else. And then, when I flip back again to shortcutList, I can go to page 1 again and so on !
Using touch: I can tap go to page 1 as long as I want, I never reach my first page but I can go anywhere else.
I extract the specific part of my project to reproduce the use case on Github, that way everyone can understand what I mean.
I hope someone can tell me why UWP Flipview doesn't flip to second item ? And thanks to try to help me to find an issue.
The problem is that the item is already in selected state, so you cannot select it again - at least selecting it does not do anything as there is no selection changed event and hence the SelectedIndex binding doesn't propagate any changes. To prove it - the same thing happens if you jump to page 4, flip back to first page and click page 4 again.
How to solve this? I think you will have to use code. This XAML solution although almost works is quite fragile. The easiest solution would be to replace the ListBox in FlipContent0Control with three simple buttons and in their Click handlers navigate to the appropriate page. For an even better approach you should try to change the app to use MVVM design pattern.
I also commited a dirty fix on Github using directions of Martin Zikmund
How to solve this? I think you will have to use code. This XAML
solution although almost works is quite fragile. The easiest solution
would be to replace the ListBox in FlipContent0Control with three
simple buttons and in their Click handlers navigate to the appropriate
page.
and a tip from Jawahar
it is because your finger is still touching the control, so flipview
cannot animate. So I gave a small break after before navigating. By
the time user would have released the finger and it works !!!
in the following post.
So, three steps to resolve :
Replace SelectedIndex in FlipContent0Control with Tapped event on each ListBoxItem inner canvas.
Provide a event on tap to raise the target index to select in the FlipView.
Add a Task.Delay(100) in the method handler of event TargetedIndexChanged

massive string array (40000) elements in listbox

I know this is a stupid question, I need to let you guys know that I am fully aware that it is useless in 99% of situations to make a listbox with this many elements in c#:
That being said I need this to be done...is there any way to populate a listbox with 40000 elements without it completely destroying performance/freezing up, thanks!
note: I have tried it, this is per the exact requirements of a professor...when adding 40000 elements through a DataSource and DataBind the application freezes up
You tell me.
for(i=0;i<40000;i++)
{
listBox1.Items.Add("click me");
}
Even if is possible (I never tried it), the usability for this form will be 0.
In that cases a more usable implementation is via lookup text-boxes and lists, where the user can enter a text to search record that matches this text and displays them in a any kind of list.
It is of course possible to do it, but not very practicable.
When using a desktop technology like WinForms or WPF, for a large number of items like this you are better off using something like an auto complete textbox, and have it set to filter/search after the user has typed two or three characters. In this case you can also use a control that offers scrolling virtualisation - this means that there is only a limited number of UI elements created in the scrolling portion of the dropdown, and those elements get reused when a scroll occurs. If you don't use virtualisation then a new element gets created for every list item that gets scrolled in to view. (Note that Silverlight controls have this functionality - just in case it's an option).
For ASP.NET though I would suggest that you do not want to do anything that would cause a large transfer of data (large items, or small items but lots of them) as it won't be performant. Instead you should look to do what Google does - retrieve search results in a paged fashion.

Paging data / infinite scrolling on Windows Phone

I want to know is there any other solution of paging data on WindowsPhone Listbox control.
I am used to paging data, by manually checking scrollbar position, and when it reaches the end of screen, then more data is loaded.
I want to ask, is there any other solution (better) of doing this (WP7 or WP8). My solution, which I've mentioned is connected with writing a lot of code (custom events, scroll listener, etc.) I think, there might be an easier solution, as WindowsPhone sdk 8.0 has been released...
The key to WP8 infinite scrolling is LongListSelector control and handling the two events:
ItemRealized (loads item) and ItemUnrealized (removes item).
This events are raised automatically based on the detected static template size(height). It is a completely automatic, on-demand action. The engine "knows" when it should get the new item or remove the old one.
Essential:
You must set the template size manually. Otherwise the count of simultaneously loaded items is unpredictable. For example if you have Image in your template it does not count as space, unless it has specific height.
ContentPresenters of List items seems to recycling. So if you change one item template from code you could magically get the new template for another item to! ;) So... Remember your ItemTemplates and set it on every ItemRealized event if you need two or more.
Unloading of BitmapImage data is pretty buggy. If you have Image in your item template, you should manually free it cache on ItemUnrealized event. And also destroy and reset binding by setting Image.Source to null. And set the original source BitmapImage to new small-sized source with minimal decodepixelwidth/height (you can't null it). I found it is the only way to fight the memory leaks. Here is the details https://stackoverflow.com/a/14225871/1449841
Binded collection for data virtualization could be as big as you want (million is ok). So you should bind that collection once and your only business will be loading and unloading items data by mentioned events.
You can use the VisualStatesGroups that are HorizontalCompression and VerticalCompression, so that you're able to detect when you're around the bottom of a ListBox.
This has been around since Mango so isn't a new WP8 feature, but definitely sounds better than your current solution of "hacky" event handlers.
Read about it on MSDN Blog - "Windows Phone Mango change, Listbox: How to detect compression(end of scroll) states ?"
If you're not avert to changing the control, there is LongListSelector, found in the Windows Phone Toolkit (note this is native in WP8) which may certainly be a better way to approach the problem, it's mentioned in the linked article that this is the new way to do what the old article got at for Mango.

Strange CheckedListBox control behaviour in .NET

I have a checkedlistbox control on a form. The multicolumn property is set to true at design time as the items are supposed to be displayed horizontally.
when I run the form and click the last item all the items shift to the left a bit which is very awkward.
Why does this happen and what can be done to stop this behaviour.
I am using VS 2008 on Win7
Regards.
Hello everyone,
setting the ColumnWidth property of the checkedListBox control fixes this. I don't know if this is THE solution but it seem's to work properly.
Maybe it's related to something going on about the space needed for the scrollbar.
Maybe you can try to disable/force the horizontal/vertical scrollbars and see if this change something

WP7 Complex Layout

I want to make a complex layout, and would like advice on the best way to go about this.
Here is the behaviour I'm looking for: Layout of some text blocks and some images, such that a tap anywhere on the layout will go to another related page to that item. I want a long list of this item in a scroll viewer.
First, I tried to make a grid, add the items in it, then add this grid in the outer grid, the main one for pressing, I made an event handler for mouse click, but a problem appeared; that when I try to scroll "on the item to view the all list" the event handler fired!, I tried the mouseButton up and down, and the same happen
Second, I'm not sure if it's an efficient way to make it.
I want a good way to design this complex layout, and of course it will be a programmatic way, and a way to recognize the item I press on.
It sounds like you're trying to create your own ListBox control. Using this will give you the scrolling functionality for free, and you can use the ListBox's SelectionChanged event to determine when an item has been clicked.
The best way to design the layout will depend on how complex it actually is. If it merely contains an image and some text, you should have no problem hand-coding that in XAML. If there's a lot more to it than that, I'd recommend looking into Microsoft's Blend tool. Whichever route you choose to produce the XAML, you will place the code in the ListBox's ItemTemplate, which determines how each item in the ListBox is displayed.
A good walkthrough of something similar to what you're doing can be found at http://weblogs.asp.net/psheriff/archive/2010/10/27/windows-phone-list-box-with-images.aspx

Categories