WinUI3 : Incrementally add contents to ListView On scroll - c++

I am working on WinUI 3 desktop application in C++. I was trying to achieve an experience where when we scroll ListView, we will incrementally add rows to the end of the listviews dropdown during runtime.
For example, I might have 100,000 results to fit in a list view, I only want to show a limited number of contents in the list view, then as the user scrolls I'll add more contents to the list view.
I was not able to get any scroll-based events in ListView directly, so I extracted the ScrollViewer from the list view and handled the ViewChanged event. This event was fired when the scroll happened. But I was not able to get how many rows were scrolled or currently which row is been scrolled.
I want to get how many rows are scrolled so that I can insert enough rows to the end of the ListViews Item Source. It would be of great help if you could help me with this.
Thank You

Related

Winforms controlling controls

I couldn't think of a coherent search term for my problem so please forgive me if this has been asked before.
I have 24 combo boxes sitting on a panel control, displayed in 4 rows of 6.
After the user defines the value for each combo and hits the "go" button, I add all combo boxes to list so I can use the values in another section of my program.
The problem is that the order the comboboxes are added to the list is messed up, compared to their visual layout on the panel, and I would like to define the order. Currently, it adds the 9th combobox to the list first then the 20th, 2nd, 16th etc etc.
I tried TabIndex but that didnt work.
Before I manually rename and relabel all of the boxes, any other suggestions will be gratefully received.
The controls of your form exist in Controls collection of the container controls, for example when you add a Panel and a Button to a Form and two ComboBox to the Panel, then:
Form.Controls contains button1 and panel1
Panel.Controls contains comboBox1 and comboBox2
Controls are added to the Controls collection, with the same order that you add them to designer. Open designer.cs, look at the end of InitializeComponent to see the order.
You can also see/change the order using Document Outline window.
That said, now it should be obvious that panel1.Controls.OfType<ComboBox>() returns combo boxes with the same order that you see in Document Outline (or based on their z-index, and it doesn't have anything to do with their x/y placements).
You may want to order them based on TabIndex, or any other property that you like:
panel1.Controls.OfType<ComboBox>().OrderBy(x=>x.TabIndex)
Note
In general, if you are going to use those values for a search, instead of relying on the order of values, a much better idea is creating a SearchModel class which has a few properties, the set those properties to the selected value of the corresponding combo box (manually or using databinding) then pass the search model to the other classes.

ListView32 - re-adding column doesn't restore data

I'm implementing show/hide column behaviour in a standard C++ Win32 application (no frameworks).
Say we've got 3 columns in a ListView control in Details view. The user has the option to show/hide the last two columns in order to see the extra detail if wanted or hide them to reduce clutter. All works well except that after the columns are deleted and then re-added, the data from the sub-items in those columns doesn't show up again, i.e. the columns are empty.
None of the items themselves have been altered in the meantime - do I lose the sub-item text when I delete the columns or I am missing something to force the columns to redraw the data?
Steps to reproduce:
1) Create a ListView32 control with 3 columns and add a bunch of items (and text to each of the items' sub-items). All good.
2) The user clicks "Hide Details", so I use LVM_DELETECOLUMN twice to remove the last two columns and they disappear. All good.
3) The user clicks "Show Details", so I use LVM_INSERTCOLUMN to add the last two columns and the headings appear, but the columns themselves are empty.
As an alternative, setting the column widths to zero is a hack and the user can still grab the re-size column splitter, so it's not a great option.
Many thanks for any suggestions.
Typically one does not store data in GUI. In case of plain listview32 you should add items specifying LPSTR_TEXTCALLBACK instead of real text and then handle LVN_GETDISPINFOW notification supplying (sub)item data. Windows will send this notification for all items. You can force Windows to retrieve data again by sending LVM_UPDATE message.
Setting the column widths is a viable solution. That is the way I do it in my UIs when columns can be shown and hidden dynamically. It works fine.
To prevent the user from resizing "hidden" columns, simply subclass the ListView using SetWindowLongPtr(GWL_WNDPROC) or SetWindowSubclass() to intercept HDN_BEGINTRACK notifications from the ListView's header control:
Notifies a header control's parent window that the user has begun dragging a divider in the control (that is, the user has pressed the left mouse button while the mouse cursor is on a divider in the header control). This notification code is sent in the form of a WM_NOTIFY message.
...
Returns FALSE to allow tracking of the divider, or TRUE to prevent tracking.

How to do dynamic paging in Grid.MVC

I have using grid.mvc control in my project. I want to use dynamic paging in grid.mvc control.
I have combobox having entries 10,25,50. when I change comboBox value. Grid should display data accordingly. ( E.g. when I select 25, grid will show 25 rows). by deafult grid is showing 10 rows at a time.
Also it should adjust while filtering records.
I tried but didn't found any suitable solution.
This in theory should be pretty easy though I haven't done it myself.
You can link that dropdown (in the view) to an action result (in the controller) that changes a value you pass to the ViewBag (in controller ViewBag.WhateverName = dropdown's value).
Then re-render the same view and in the place when you end your grid, end it with
}).WithPaging(ViewBag.WhateverName)
Basically .WithPaging(10) would give you pages with 10 rows, WithPaging(20) 20 rows per page, etc. So by changing that value with the dropdown and registering that action in the controller to reassign the value, you should be able to achieve this functionality.
I will keep editing and maybe add controller code later if I have time, just wanted to get something up to help you out. Good luck!

QTableView re-focus the view to specific column

I have a QTableView with 80+ columns displayed in it. The subclass i have created for QTableView allows has functionality for the standard table stuff i wanted e.g order by columns move columns and rows hide column and rows etc.
However the problem i have is the view's focus. lets say you have all the data in the table, you scroll all the way to the right so you are looking at columns 70-80 (assuming 10 columns fit on the screen at once) if i click the header of row 80 (to order by column 80) the table reorders (as expected) however it also jumps the view to the last focused cell (which as far as i can tell is the cell that was last clicked)
What i want to do is not necessarily refocus on the column that was clicked because this might still change the view what im looking for is to just keep the view's focus exactly as it is instead of having it jump back to where the last clicked cell was?
Is there some flag im missing for focus policy or will i need to get the current view and set the view back to that view after mouse clicks that reorder the table and if so how could this be done.
Im aware i have provided no code for this question but it doesnt seem there is any needed since its not a bug im looking to fix more of a feature im unaware of, if you want to see any just comment
EDIT:
Im using a QSortFilterPorxyModel, this seems to get set once (when i call this->setSortingEnabled(true); after the initial call to this on contruction my table model never calls sort again. I have a slot linked to the header clicked signal, and i set the scroll bars to scrollTo() to the index clicked, but i think the sort is happening after this so it does nothing, any idea of what signal are emitted after sorting so i can catch them and then set the view back maybe?
thanks
Before you do your sort, store the current values for where the scroll bars are with
int vPos = yourQTableView->verticalScrollBar()->sliderPosition();
int hPos = yourQTableView->horizontalScrollBar()->sliderPosition();
then after the sort, set it back
yourQTableView->verticalScrollBar()->setSliderPosition(vPos);
yourQTableView->horizontalScrollBar()->setSliderPosition(hPos);
The signals you are looking for are signals of QSortFilterProxyModel inherited from QAbstractItemModel:
layoutAboutToBeChanged()
layoutChanged()
I couldn't reproduce your symptoms by creating a QTableWidget, filling it up with random stuff, and then sorting a particular column. The selected cell stays selected, but does not become visible if it has scrolled off screen.
So the question is, what is causing the behavior you're seeing. It sounds as though scrollTo() is being called by some other function. Since that's a virtual function, I would override it with a pass-through function and see when it's getting called.

How to create an image slideshow in an xe:Dialog?

I am trying to create a slideshow in an xe:dialog
within the dialog I have repeat populated from a notesdocumentcollection containing one image for each document. and two buttons. Next and Previous
When the user in the dialog click "Next" the next image in my collection should be displayed and when I click previous the previous image in my collection should be displayed.
As these images can be very big I do not want to preload them, the actual image should be retrieved at the time when the user click the "Next" button.
How can I do this?
the problem I have is that I do not know how to navigate to the next image. there is probably a very simple solution. I have tried using different techniques like setRowIndex and setIndex etc.
I first thought I could set the repeats repeat limit to "1" and then navigate to next by incrementing the index but could not get that to work.
So what I thought about then was to set the repeat limit to 1000 and hide all images using css but then all images would be preloaded.
Instead of document collection, you can store document id's in a vector and put it into viewscope. You also put a current index in the viewScope. Next/previous will change index variable and since xe:dialog supports partial refresh, it will be easy and convenient.