Proper display of custom QItemDelegates - combobox

I am trying to use simple example code I've found in Google.
Everything works except as soon as I set the delegate for the column, it's displaying gets buggy.
Here are the line where I set the "Bank" string as a value for both rows and comboboxdelegate.cpp
Here's a screenshot of MainWindow
The question is, if the data is stored in model, why is it not displayed properly? Because if I change the value using combobox, what is displayed in cell still stays as shown in screenshot. However pressing button shows that data in model has been changed
P.S. I am not concerned about editor not being persistently visible, I'm concerned about displayed cell value being something else.

I had to change the line QString text = items[index.row()].c_str() to index.data(Qt::DisplayRole).toString().
So while painting the delegate Qt will access data stored in model, not in delegate's option vector
I also had to change model->setData(index, _editor->currentIndex()); to model->setData(index, _editor->currentText());

Related

Populate DataGridView from ComboBox.SelectedItem on Button click

I have one ComboBox which is populated on load from populate.txt file. I'm using streamreader for this. So far it works. The ComboBox is properly populated with:
- one
- two
- three
I have one empty TextBox, and a button.
The thing that I'm trying to do is:
Select something from the ComboBox i.e. "one"
Write in the TextBox i.e "50"
Press the button, and to populate the DataGridView first row with:
"One"(cell0) "50"(cell1)
At this point, a new empty row should be automatically added below the filled one. I've searched and searched for hours to no avail. So I decided to make an account and ask the question :)
The reason I'm doing this is that, later on I'll export the filled DataGridView.
I could easily use labels for this, but that's not what I'm aiming for. I'm trying to "dive in" into the more complicated "stuff".
I hope that I explained well enough.

DataGrid selected item changed more quickly than data loads from DB

We have the following WPF : a datagrid with row detail template. Selected line on this grid (customer selection) is handled to trigger two queries to retrieve address and contacts data, then row detail template show these data in two tabs, each with a datagrid. All the magic is done with binding, subgrids bind to properties of main Customer object, which we have as an IObservableCollection.
The bug happens when using “move down” arrow on keyboard, selected index changes fast, so fast than queries result “come back late” to interface, thus data is incoherent to what is shown and data update cannot perform. We have an exception. So my question is : how to prevent this in a proper manner ?
Should we have a try-catch the right kind of obscure exception then do nothing (loose data that cannot be applied to interface) ?
We don’t want to wait for data to come back, if user scrolls very quickly, customer selected line should go down and no matter details aren’t shown.
Maybe we should have a delay before selected item details are retrieved ? Thus no query if selected item changes before end of delay ?
Thank you for your ideas.
Gists for code:
Xaml : https://gist.github.com/Xarkam/3b89eb614124bb2f2307
Selected index changed handling : https://gist.github.com/Xarkam/cf28844ce05fd4984807
Edit 10th of July :
I have modified the main datagrid items definition as in following gist : (add https:// prefix, I don't have enough reputation to add more links, sorry) gist.github.com/postb99/d3be79f0ef2544d685f9 (inspired from stackoverflow.com/questions/13374957/datagrid-throws-invalidoperationexception-by-scrolling and proposed answer) but problem still persists...
We've solved it, if I remember well we didn't have observable collections for every collection of objects to display.

Getting current page of a FlowDocumentPageViewer

I have a FlowDocumentPageViewer control that I am populating from the code behind. I am adding text from 3-4 items. I need to know on what page item 1,2,3... ends.
These items get added to a FlowDocument in a loop and then at the end I have
flowDocumentPageViewer.Document = resultsDocument;
However, even then if I call
flowDocumentPageViewer.PageCount
I still get 0. If I do some event like a click and print the above PageCount after the window renders, it does print the correct value. However, I need a running total of this value as I populate the FlowDocument. I am hoping someone knows some kind of trick with text metrics or any other way that this could be solved.
You have no choice but to trigger a (virtual) render of your control to get this kind of info.
the easiest way is to force a updateLayout() on the FlowDocumentPageViewer, but this means it'll show the result before you get the info which is probably not what you want.
you can also use the Arrange() method if you don't want the content to be shown:
http://msdn.microsoft.com/en-us/library/system.windows.uielement.arrange.aspx
after using this on your control you should get the updated info.
I had the same problem and to be honest I still do. Any updateLayout() did not help. Now I use a timer to get the pagecount a second later after I assigend to document to the viewer. Works fine.

How do I save data created in a form in Access 2003 when I reference other tables?

I'm not sure how to fix this issue, but when I utilize combo boxes on my form which selects data from multiple tables I'm not able to save any of the data selected.
I tried to use the Bound form utility but it only asked me to "Enter Parameter Value". I took out the "Bound" portion of the code and the combo box works fine.
I have a nice little save button, but it doesn't actually save anywhere.
I tried using a query, but that didn't fix it either unless, of course, I didn't do the query correctly.
Here is the "Row Source" information...
SELECT SubArea.SubAreaID, SubArea.SubAreaName, SubArea.ProductName FROM SubArea WHERE (((SubArea.ProductName)=Forms![Combo Form]!Product));
Do I need to put something in VBA or perhaps a Macro to have all the data selected to actually save into a table? HELP!
For the Bound Form
Open the form in design mode, right click on the combo box and go to properties. Check out if it is actually bound to something in the Control Source field.

WPF -- Displaying Image in RadGridView dynamically and through code

I have a radgridview which is bound to an object that I created, foo.
Object foo has a property 'status' that is populated from an enum.
I have many foo objects stored in a collection, which I use to bind to my radgridview.
Upon binding I get records and the grid displays fine.
I'd like to not display the 'status' enum value from my foo object within the grid. Instead, I'd like to use separate images that will depict the status more clearly (and in less space). Example, if foo's 'status' enum value == Open, I will display an open door and value == Closed would be a closed door. So the same column could have different images, but from the same property bound by foo's status enum. Hopefully that's clear enough...
I have tried overriding the content value with a bitmapimage within the RowLoaded event of the grid. I have also tried setting the data type of the grid to image, butmapimage, and image source to no avail...
Seems like this should be much easier than it is... If the image came straight from the database, it wouldn't be a problem; there's plenty of examples out there. However, doing it dynamically AND through code remain a mystery.
Thanks in advance for any assitance!
Apparently all I needed was to post the question...
I fell victim to trying way too many things at once and a soultion that should have worked perfectly didn't because I was trying a style on a cell at the same time.
In the example provided above, within the grid's RowLoaded event, one could do the following:
Get the enum value from the cell content
Create an Image control ( System.Windows.Controls.Image img = new Image(); )
Assign the image's source depending upon the enum value ( open.png / closed.png )
Set the cell's content = to the image control you just created
When the grid displays, you should see your image in the grid cell...
You also need to ensure the column's datatype is set to:
typeof( System.Windows.Controls.Image )

Resources