Find Duplicates from tree list in Dev-Ex - devexpress

I have a Dev-Ex Tree List which has two columns, List contains elements inside it, Now My question is if i want to add any new item in the list then logic should search existing items in the tree, if no match found then it should allow to add that item in the list,otherwise not.
can i make a method which keep on checking recursively new item with the other item in the list.

Such tasks are usually solved by using TreeList Iterator. I think that the How to Implement an Iterator for the XtraTreeList (FindNode Example) knowledge base article contains the code you are looking for.

Related

What are differences between index and item method of QStandardItemModel?

My friends, Could you please explain the concept of these methods to me? Normally, when I get a data I would use 'index' to refer to items in a model and specify roles via data attribute. I came across 'item' method today and the explanation of this method is "Returns the item for the given row and column if one has been set; otherwise returns 0." What are differences from 'index'+'data' method? Is it just a shortcut?
This is the documentation of 'item' method.
https://doc.qt.io/qt-5/qstandarditemmodel.html#item
Alternatively, this is the documentation of 'index' method.
https://doc.qt.io/qt-5/qstandarditemmodel.html#index
I'll try my best to explain it.
The item is like the actual widget you see in the view (it's not actually a widget, but I think it's a good way to think about it). It's what the user is actually seeing.
The index is more "behind the scenes." It's like a pointer to a position in the model.
An item can exist without an index. But a valid index cannot exist without an item. The item only associates with an index when it is put into a model. Otherwise, it's just an item that no one can look at.
Take an array as an example... It contains multiple "items". You specify which item from the array you want by providing a number, aka the index. Simply put, the index only exists when it is associated with an item in the array. But the item can exist outside of the array and be it's own thing without an index.
The QModelIndex was created to be a lightweight way to reference items in a model. Similar to the way you can use a number to represent an object stored in an array.

Iterate over expanded nodes of QTreeWidget

I have a QTreeWidget. Have to iterate through the nodes which are expanded. Tried with iterating with QTreeWidgetItemIterator it(<rootNode>, QTreeWidgetItemIterator::NotHidden). But it is giving all the nodes of the tree instead of just expanded ones.
Am I missing to set any flag in the iterator?
I am afraid there is no specific flag for expanded items (but you can get checked items, for instance, using flags, http://doc.qt.io/qt-4.8/qtreewidgetitemiterator.html).
But you can easily check if item is expanded or not while iterating, using QTreeWidgetItem::isExpanded()

How to filter the data provider for a tree?

I have a requirement to filter the tree similar to that of flex builder-->preferences wizard tree.
My tree dataprovider is arraycollection of industries. Each industry has a list of sub industries and further, say upto depth 5.
So when we type in a string to filter, only the node having this string along with their parent hierarchy should be returned.
How can we implement this using flex?
I would write more but I think this link is all that's needed, essentially what it comes down to is you can use a filterFunction that's able to recursively act on the collection. If you need more direction please specify where you're stuck and what your original data set looks like.
http://www.kalengibbons.com/blog/index.php/2009/01/filtering-a-flex-tree-using-an-arraycollection/

AdvancedDataGrid (grouping) quick jump to row

I have a problem with the AdvancedDataGrid widget. When the dataProvider is an ArrayCollection (of arrays), the nth array (within the collection) is also the nth row within the grid, and I can jump and display the i-th row by scripting
adg.selectedIndex = i;
adg.scrollToIndex(i);
now, when I add a Grouping, the dataProvider ends up being a GroupingCollection2, and now the index in the dataprovider's source does not correspond to the index in the adg anymore (which is understandable, because it's being grouped).
How can I select and display a row in grouped data efficiently? Currently, I have to traverse the adg and compare each found item with its data attributes in order to find the correct index of the row within the adg, and jump to it like above. This process is very slow. Any thoughts?
edited later:
We already used a caching object as Shaun suggests, but it still didn't compensate for the search times. In order to fully construct a sorting of a list of things (which this problem equates to, as the list is completely reordered by the grouping), you always have to know the entire set. In the end we didn't solve that problem. The project is over now. I will accept Shaun's answer if no one knows a better way in three days.
Depending on what values your comparing against you can store the objects in a dictionary with the lookup using the property/properties that would be searched for, this way you have a constant time look-up for the object (no need to look at every single item). Say for example your using a property called id on an object then you can create an AS object like
var idLookup:Object = {};
for(myObject in objects)
idLookup[myObject.id] = myObject;
//Say you want multiple properties
//idLookup[myObject.id]={};
//idLookup[myObject.id][myObject.otherProp] = myObject;
now say the user types in an id you go into the idLookup object at that id property and retrieve the object:
var myObject:Object = idLookup[userInput.text];
myAdg.expandItem(myObject, true);
now when you want to get an object by id you can just do
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/AdvancedDataGrid.html#expandItem()
I haven't done any thorough testing of this directly, but use a similar concept for doing quick look-ups for advanced filtering. Let me know if this helps at all or is going in the wrong direction. Also if you could clarify a bit more in terms of what types/number of values you need to lookup and if there's the possibility for multiple matches etc. I may be able to provide a better answer.
Good luck,
Shaun

In Flex, how do wrap Lists into columns?

How do you make a List control wrap around to a second column (or multiple columns)? Thanks, let me know if there is a solution for this with the List control or some other Flex control.
For example, if you have one list with 42 items in it, but I want to cap the height of a list to 20 items; then instead of having one list with 42 items all the way down, I would have that list of items look like the equivalent of 3 adjacent lists: the first with 20 items, the second with 20 items, and the third with 2 items (which represent the original list of 42 items).
This question seems similar but it is in ColdFusion:
Wrapping lists into columns
Using a TileList and changing the direction variable is the best solution I have come up with.
You could use a Repeater and a simple Label based itemRenderer for the list items and avoid using a list completely. If you wrap it all up inside a custom control you can provide the same API as List so your consumers will never tell the difference.
I think you're looking for a second row, as others have noted. Either setting the wordWrap to true or using a different item renderer are the best way to get it done, but using a custom item renderer will give you more control over how the object is displayed.
I suggest creating a custom Component that wraps a variable number of Lists. This custom component can have a property named "maxListHeight". It can also have a "dataProvider" property. This custom component will produce a set of horizontally aligned lists. The number of lists produced by the custom component will be: floor(dataProvider.length/maxListHeight)+1. Where all but the last list produced will have a listHeight of maxListHeight; the last list produced will have a listHeight of: dataProvider.length % maxListHeight.
This should work but managing the addition and removal of items to the masterList should require some extra work (if it is not appended/removed from the back). This would also require instantiating multiple lists instead of just one.
The default itemRenderer for a List control is TextInput that supports only single line text. Use TextArea instead.
<mx:List itemRenderer="mx.controls.TextArea"/>
Try setting the following two properties on List:
wordWrap=true
variableRowHeight=true

Resources