Recreated active item doesn't get added to any container - sencha-touch

I've encountered this in a couple spots in my app:
Let's assume I have 3 items in a carousel. I'm viewing item #2. I need to reload that carousel, so I do the following operations:
Ext.getCmp('carousel_name').removeAll();
var new_objects = (bunch of code that recreates the carousel's objects again, with the same IDs; this is the same code that was used to create the objects the first time, so it is likely not the issue)
Ext.getCmp('carousel_name').add(new_objects);
In the carousel object items list (Ext.getCmp('carousel_name').getItems()), all three items exist. However, only #1 and #3 (the ones which weren't the active item prior to the carousel reload) actually appear. #2 presents a blank white screen, and in the HTML nothing exists except for the item shell markup (no code that I've written shows up). If I do Ext.getCmp('carousel_item_2').show();, the item does appear, but is full-screen, and I get the error:
[DEPRECATE][Ext.Panel#show] Call show() on a component that doesn't currently belong to any container. Please add it to the the Viewport first, i.e: Ext.Viewport.add(component);
When I try to manually add that item to either the Viewport or the carousel, nothing is fixed.
I've tried inserting a dummy item in-between removal and reinsertion of new items, that doesn't work. Nor does hiding the entire Viewport before doing any of this and showing it afterwards. Nor does using setItems() rather than add(). Nor does doing Ext.getCmp('exercises_carousel').each(function(item){ item.destroy(); }) rather than removeAll(true)
I don't believe the issue is the code snippet that re-creates the new items, since it's the same code that's used to create the items the first time, and there are no issues on the first creation.
Pretty stumped here.
EDIT: I've found that if, when I get to the end of the carousel, if I add a empty item after the last item in the carousel, I don't get the blank item at N-2. No clue why this is the case. Still not a real solution, it's a hack.

Assuming there are no problems in your code snippet to re-populate new items in your carousel, then the only problem is because of this issue (I'm not sure whether it's a bug in Sencha Touch 2.1 or not but it does exist): when you call yourCarousel.removeAll() and add some new items again, your carousel will NOT set proper active item.
I've seen a similar problem and I added this after adding new items, which works:
carousel.setActiveItem(0);

Alright, this is a hack, so if anyone has a legitimate solution, that would be awesome. But the hack does work, so here it is:
Add an empty item in the carousel
Set active item to the new empty carousel item
Destroy all carousel items
Recreate (and re-add) all of the items
In code:
Ext.getCmp('carousel_name').add({});
Ext.getCmp('carousel_name').setActiveItem(Ext.getCmp('carousel_name').getMaxItemIndex());
Ext.getCmp('carousel_name').removeAll(true);
var new_objects = (bunch of code that recreates the carousel's objects again, with the same IDs)
Ext.getCmp('carousel_name').add(new_objects);
EDIT: As it turns out, this for some reason works 90% of the time; for some unknown reason 10% of the time it still doesn't get inserted. The only way to guarantee that all items get inserted correctly is to clear the entire viewport (Ext.Viewport.removeAll(true)), recreate all of the original items in the viewport, and reinsert them. I'd rather not have to do this every time an item doesn't get inserted.

Related

VBA MSHFLEXGRID wrong .ROW information in the CLICK event

I'm using the VBA MSHFLEXGRID, 2 grids in fact in the same Form, one below the other so when I choose a row in the first grid, the second one shows info regarding the first grid row selection.
Well, the problem is that the second grid, after choosing a row in the first grid which brings to no information in the second one (I put the data through the own grid recordset, and if i dont want it to show information, i do an exit in the load procedure, it gets crazy and the .ROW property in the Click event starts returning a fixed number, like for example 4, instead of the actual row being clicked. Always a number that represents a higher row than the last one (one that is even out of the grid). I tried also the .MOUSEROW and this one returns 0 all the time (when the grid becomes crazy).
This never happens with the first grid, only with the second one. There's nothing I can do without real information about the row being clicked. I've seen that with different resolutions the problem gets reset. Seems not to happen with low resolutions like 1360x768, but it does with 1920x1080 and 2560x1440.
SOLVED! I was trying cases and more cases to try to understand why it happens sometimes in random cases and finally found it. The problem appears when you set the recordset directly to the grid (Set Grid.Recordset = xxxx) and this xxx is empty. It is, EOF. So I was doing a .Clearstructure, and then the SET. After this, if i did another SET (another selection of the second grid) with a non empty recordset, then it would go crazy.
So what I did was simple assigning first a recordset object to check if the SQL query is empty or not, and if it's not empty and only then, assign the recordset to the grid. Oh my god, this was bringing me crazy after a long time.

Loop through items in "Bar styles", reading items

I'm basically interested in checking if the user is showing any baselines in his active view, and if yes, which one.
If for instance "Baseline1 Start" is used in Bar Styles for the active view, I'd find the matching item number.
If I were able to loop through each bar style item, such as the built-in list MS Project shows lists under "Bar styles", that would solve my problem.
I've tried using the GanttBarEditEx method, but as the documentation explains, it only returns boolean.
If I for instance want to delete an item, this code will do:
GanttBarStyleDelete Item:="41"
My problem is that I don't know what Item I'm looking for. I don't know how to read data about Item:= "41"
This code is not working, but illustrates what I want:
For i = 1 to 200
if GanttBarEditEx(item:=i, from:"Baseline1 start") = True Then MsgBox i
Next
I'm able to figure out the item count using the same logic, when item = i returns an error, that means there's no such item and I have found max. That's how far I've gotten.
There's also a code for GanttBarStyleBaseline which could be of help!
If it's impossible to list the items, I might be able to write a code that's sets each baseline to false, then check if a change was made to the active view, and hence find the active shown baseline...Help?
Update: I noticed that BarBoxStyles opens the "Bar styles" window. But I'm guessing that can't be turned into a collection for looping.

Editing SWT Table cell. Changed value jumps back immediately to old value as soon as I leave cell. Why?

I have a Dialog and there is a Table (Tableviewer) inside it.
tableViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI);
Certain columns of my table are editable. I click on the cell, I edit the value, I leave the cell and the edited value immediately reverts back to the old one.
What should I configure/set in table/tablehelper to make the edited values last longer than the time I spend in the cell?
EDIT!-----------------------------
We have a Helper class that is responsible for creating CellEditingSupport like this:
`
if ("w".equalsIgnoreCase(hd_bean_mode)) {
CellEditingSupport editingSupport = new CellEditingSupport(viewer,pds[i]);
col.setEditingSupport(editingSupport);
}`
This class itself is quite complex and does a lot of magic through reflexion, etc... The funny thing however is that other tables use this very same Helper class, seemingly with the same configuration and they work!
One more thing: I am conviced that the columns in my table get the Editingsupport. I know it because of the debugger and because the cells are editable. The only problem is that those edits do not last long.

WinForms context menu really slow adding 150 Toolstrip Menu Items

I have this code that add items to a context menu's sub-menu:
CTX_VALUE.Enabled = True
CTX_VALUE.Visible = True
CTX_VALUE.Text = "List Values"
For k As Integer = 0 To CELL.VALUE_LIST.Count - 1
CTX_VALUE.DropDownItems.Add(CELL.VALUE_LIST(k))
Next k
Where CTX_VALUE is a ToolStripMenuItem
and CELL.VALUE_LIST is an ArrayList (yeah, old code!) of ToolStripMenuItems
When it comes to add about 150 items, it becomes really slow, about 2.5 seconds.
Visibility before adding doesn't matter, i tried moving it after.
BTW, note that the context menu is not on screen when adding items!
I also tried suspending layout of CTX_VALUE before adding. No luck.
you should add these using CTX_VALUE.DropDownItems.AddRange() method
Before the add items loop I used both
ts_filter.DropDown.SuspendDrawing (see addendum note below)
and
ts_filter.DropDown.SuspendLayout
After the loop I used the corresponding resume methods.
This made a huge difference to my program moving it from unworkable to instant.
Addendum:-
The resumedrawing (alone) was preventing my custom textbox (inherited from toolstriptextboxfrom) from showing. I found the suspendlayout and resumelayout to be ok alone though and it kept the speed up.

Programmatically set dgrid row as active

I'm trying to programmatically set a dgrid row as active, not just selected. I have a dojo dgrid OnDemandList which is using the Selection and Keyboard Mixins.
Using the select(row) method I can programmatically select a given row, but that row is not active. When a row is active, I can use the Up and Down arrow keys to navigate to the rows above and below it. When a row is just selected, the row is highlighted but the arrows keys do not work.
Clicking the row with the mouse will make it active and selected, but I'm trying to build my interface to be 100% usable with just the keyboard.
Ok, took me awhile but got it figured out. What I was really trying to do was add focus to a row. The code for doing that was in dgrid/Keyboard.js under the _focusOnNode method.
The actual code to change focus from row currentFocusedNode to row focusedNode is:
if(currentFocusedNode){
// Clean up previously-focused element
// Remove the class name and the tabIndex attribute
put(currentFocusedNode, "!dgrid-focus[!tabIndex]");
if(has("ie") < 8){
// Clean up after workaround below (for non-input cases)
currentFocusedNode.style.position = "";
}
}
if(has("ie") < 8){
// setting the position to relative magically makes the outline
// work properly for focusing later on with old IE.
// (can't be done a priori with CSS or screws up the entire table)
focusedNode.style.position = "relative";
}
focusedNode.tabIndex = grid.tabIndex;
focusedNode.focus();
put(focusedNode, ".dgrid-focus");
The code above is really just a code fragment, for it to work you will have to declare "dojo/has" and "put-selector/put" first as well as define the currentFocusedNode and focusedNode. But I'm leaving that as an exercise for the reader ;-)
Also note that this only changes the "focus", it will not select the focusedNode but that can easily be done using grid.select(focusedNode);