Scroll to item in view, but do not scroll to view - c#

I'm developing a WPF application, containing multiple ListView's.
Every view has a button, and the user can press it to initiate a function that processes the items in the view.
The item count is often up in thousands, and can take a couple of minutes to process.
Now, I want the item currently being processed to be selected and scrolled to so the user can get a hunch of how much has been processed.
This in turn also makes it easy for the user to know what item causes the processing to stop in the event of an error, as it is selected.
To do this I have bound the ListView's SelectedIndex to my ScrollRow property, which i set in my processing function.
I then scroll to the selected item using the event SelectionChanged, which runs a function that calls ScrollToView on the selected item.
My window contains many views, so there is often a scrollbar on the main window containing the views.
The problem is that when I call ScrollToView on a row in a view, the main window also scrolls to this view, when the user wants to look on another view further down in the window.
I have looked into setting the scroll position directly, but haven't found any ways to do that.
How do I prevent the window to scroll when a view in the window scrolls?

I'm not sure the user will like to see a listbox animating itself other a thousand item.
Rather a little info panel on current processing displaying % progress, current item, time...
But but but.... i'm not here to question your design choices :-)
So what you should do is to get the scrollViewer of your listView, and call ScrollToVerticalOffset on it to have the content to scroll without stealing focus.
To find the scrollViewer, you might use my answer in this question :
How do I get the start index and number of visible items in a ListView?
If you want to go for a more xaml/binding solution, you might expose VerticalOffset using this kind of solution:
http://marlongrech.wordpress.com/2009/09/14/how-to-set-wpf-scrollviewer-verticaloffset-and-horizontal-offset/

Related

TextBox receiving focus when clicking on ListView

I'm struggling to make a custom autocomplete style control for my application using a list view. In one form, the custom control is working as expected, however in another, when clicking on the ListView, rather than the ListViewItem being selected, the first TextBox in the form is selected instead.
Rather than clog up the question with a wall of code, here is the code for the AutoCompleteListView.
Here is an image of the form. Items are redacted due to data protection:
Also, here is a .gif showing the behaviour of the form. What I'm doing in the aformentioned gif is attempting to click on the first item within the ListView, however, as I do that, focus changes to the first text box in the form. This same behaviour occurs when clicking on any item, in any of the 3 text boxes.
I have attempted to trace the events using RuntimeFlow to watch as events fire, but it has not provided any clarity as to what is actually happening. If anyone could point me in the right direction, that'd be greatly appreciated.
My first guess is in ItemClick you are setting visibility to false, which means something else in the form needs focus, ie the textbox. So do a textbox.focus() in ItemClick to the desired textbox. And given that you will not have access to the parent form in this class, I recommend you make an OnClose event in the AutoCompleteListView and subscribe to it in the parent form, to set the focus to somewhere.

How make an area on win form scrollable?

Items like below have to be accommodated on a specific area on WinForm.
"Order 1 ------------ Time Left: 00:20:00"
"Order 2 ------------ Time Left: 01:30:20"
We should be able to perform the following action on the each order:
Each item will occupy not more than one line. As the area specified
for it on the win form is limited, as more items comes in, I want to
make the area scrollable.
According to the time left the background color of the line should also change.
There is a DONE button next to it. So, if the item is selected and DONE is pressed, the item is moved off the list.
My question is what C# Form control can be used for it. I was thinking of labels, but how to make the area scrollable if there are many of them. If not labels, what else is suggested?
As suggested in comments, you can use grid, but in case it does not suits your requirements, this is like something what you can do -
Create a custom user control which will have a label control for your order detail and a Done button. Something like this (sure you will design it better!). The label will be empty initially and you will pass then from outside, using a public property for example, while creating the control.
Define an Event on this control, and raise this event when the Done button is clicked. This is required for your main form to know that when to remove this user control.
Add a FlowLayoutPanel to your main form. This will be the container for your user controls. Make sure to set the following so that the controls are created as desired
this.flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
this.flowLayoutPanel1.WrapContents = false;
this.flowLayoutPanel1.AutoScroll = true;
Now you can start adding your custom control to this FlowLayoutPanel, either by loop or the way you like. The control will added in linear way, one in each line, and you will also get scroll it it exceeds the given space.
Make sure to define event handler for the control, so that you know when to remove the control. And of course you can set other properties like back groung color etc. That's not going to be any problem.

Flicker of Mouse in TextBox , Graph while Processing Large Data in other UI Control

My Application processes large data Entries and display each group of entries in Tree List View.
The Main Form has other Controls such as Text Box "Used as Filter for Entries" and Graph "Displays Entries Data"
Every thing work Great , The Problem is while Processing Data entries and Displaying on TreeListView if i places the Mouse on textbox or graph , it keeps flickering and blinking ! , i can write data successfully to textbox but it is always flickering.
Take into consideration that The function of handling that large data entries and display on TreeListView is in separate thread.
so what is the problem here ? and how this separate thread affects rest of other controls in my mainform ?
One solution: Make everything Visible = false until your processing finish up, then Visible = true. You can also display a message "Please wait" while the items are hidden.
Another solution: avoid on-ui-thread long operations. Avoid fast add/delete into listview or treeview. It is better to clear everything then add everything. Yo can also hide your treeview, add items to it, then show it.

Prevent ContextMenu on ListViewItem from disappearing when changing Filter

I have a ListView and TextBox for entering search text.
When the user searches for some text, I start a long-running search operation (on the UI thread, through a UI-thread-timer), and every now and again, while the search is still active, I change the ICollectionView.Filter property, to cause the ListView to refresh and present more items that the search has found as matching.
The problem is that if the user right clicks on one of the items, and then as Search is happening in the background, the tree is refreshed, then the ContextMenu disappears.
How can I prevent that from happening?
Here's my theory:
Because the whole tree is refreshed, WPF cannot know that the item (which was right-clicked) is the exact same item as after the refresh. Technically, that Item isn't even "there" anymore. It's really a new item with the exact same properties (from the ListView's perspective).
There are a some ways you can try to remediate this:
Capture the right-click of the item, store the item; capture the tree refresh, check if the item is equal to the stored item; if equal show the ContextMenu.
Instead of refreshing the whole tree, add items to the end of the list.
While ContextMenu is open, suspend refreshing the tree.

Silverlight combobox blocks interaction with other controls

I have a Silverlight view which has several layers of popups. It is a record search/edit page, which displays the results in a datagrid. There is a details view for each record that is then shown in a popup over the grid. Finally, the sections in the details view can be edited, and the edit form is displayed in a third popup. The search criteria is hidden when viewing data, but can be toggled into view.
The problem I am facing is that whenever the comboboxes on the edit popups are interacted with, it causes the layers below them to be un-clickable. In the screenshot I provided, if the user clicks on the Phone or Email comboboxes, even if they don't change the selections, and closes the topmost edit popup, then the delete, save, close, and view on map buttons no longer receive mouse interaction. They have mouseover styles that are not applied and they don't receive clicks. However, the New Group button does, but only below a certain point. It is behaving as if there is an invisible canvas/shape blocking mouse interaction.
Additionally, if the user slides out the Record Search panel (by clicking on the down arrow icon), the form somehow gets reset and those buttons are clickable again. Also, if the browser window gets resized the buttons are also clickable.
I've spent the better part of two days going through this, admittedly complicated, view and I'm positive there are no controls/canvases/shapes that I'm displaying that are being placed in the way, as I've added color/outlines to every canvas in the xaml.
At this point I am stumped and reconsidering redesigning the form to avoid this problem. Has anyone run into this and if so do you have a solution?

Categories