remove duplicate VB.NET TreeVeiw node - vb.net

any hint on how to add only one node to TreeVeiw control while many nodes with same name found in access database field ?
I can loop through the field but all the values add to TreeNode which is why i wanted to remove the duplicate.

Loop through the items and store them in an array while doing so.
If the current item in the loop, already exists in the array => duplicate => remove
You could try that, good luck.

Related

How delete Item from ArrayList in Firestore using Koltin

I want to delete one item from the animeId. For example, if I need to remove the animeId[5] or I want to remove the item that the value is equal 5114, how can I do that? I alredy learned how I remove item like the entire animeIdbut not just one item.
Here's an print how the database is organized:
For updating some fields of a document, use the update() method.
If you want to remove a specific item from an Arraylist, you can use a call to:
.update("arrayfield", FieldValue.arrayRemove("itemtoremove"))
For example if you have an arraylist that contains three items as “abc”, “efg”, “xyz”.
And if you want to remove specific item called “efg” from an arraylist you should use a call to:
.update("arrayfield", FieldValue.arrayRemove("efg"))
Please also take a look at this Stackoverflow Link which explains clearly on
how to remove specific items from the array list in the firestore using kotlin.

HandsOnTable (Vue Wrapper) - Associate row with database id?

I'm trialling HandsOnTable via the Vue wrapper to make a simple database editor. I can populate the table easily, however I now need to save changes back to the database.
If I use the afterChange() method hot will give me the changes in the cells that have changed, however I need to be able to associate those changes with a database id to send them back to the server. Any idea of how to do this, and also is it possible to get the changes associated with a row? Would it also be possible to do this without displaying the database id to the user in the table?
To answer your main question, you can associate metadatas to cells. So you can put your technical id in your first column for example or a hidden column (or whereever you want).
hot.setCellMeta(0, 0, 'myIdName', 'myIdValue');
where "hot" is your Handsontable instance. (documentation reference)
You can then access getCellMeta(0, 0).
Second question :
and also is it possible to get the changes associated with a row ?
You already are able to get the changes of specific rows by filter the changes in the afterChange hook. Taking the example from Handsontable documentation this is how you get the row :
new Handsontable(element, {
afterChange: (changes) => {
changes.forEach(([row, prop, oldValue, newValue]) => {
// Some logic...
});
}
})
As you can see changes is an array of change that contain row and col (prop).
Hope this helps.

odoo filter one2many list

I have a long one2many list and want to show only a subset of this to the user, based on filters that the user may set.
My current approach is to have the original one2many field with all records, and another filtered one2many field.
I compute the filtered list by selecting the subset that is not filtered from the original list.
Further I apply the changes from the filtered list to the original list. So I search for new records in the list and create those as well in the original list. I search for deleted records and delete them from the original list.
This approach works actually, but it requires a bunch of code and only mimics what I would expect from either some native Odoo features or a filterable one2many widget.
Sadly all other approaches I tried did not work:
Searching in one2many lists does not work (e.g. setting search_default_ values in the context). I think it is not supported.
Using a domain to filter the second one2many list does not work (neither in xml nor python code). I think Odoo only allows this for many2many.
I would like to create a filterable one2many widget by extending the normal one. However I don't understand where in the js code the list is populated.
So question is: Is there an easier solution than my current approach to filter a one2many field with native Odoo features?
Or can you help me with the js code of a custom one2many widget to only show a subset of items? For instance, which method is called when the list is populated and in which field are the ids of the items?
Example
I want in my model something as the following:
# This is the original list, with all entries
schedule_entry_ids =
fields.One2many('mymodule.schedule_entry', 'schedule_id', string="Entries")
# This is the filtered list, to be used in the view
# Note: Sadly using the domain here does not work. It always shows all entries. But I hope you get the idea what I want to accomplish.
filtered_schedule_entry_ids =
fields.One2many('mymodule.schedule_entry', string="Filtered Entries", related='schedule_entry_ids', domain='[("phase_id", "=", filter_phase_id)]')
# This is the field that defines the filter
filter_phase_id =
fields.Many2one('mymodule.phase', string="Phase Filter")
Sadly using the domain filter does not work, so my approach at the moment is to create the filtered field as a computed field 'by hand':
filtered_schedule_entry_ids =
fields.One2many('mymodule.schedule_entry', string="Filtered Entries", compute='_compute_filter', inverse='_inverse_filter')
#api.onchange('filter_phase_id', 'schedule_entry_ids')
def _compute_filter(self):
# Populate the filtered list with the elements from the original list, for which the filter condition holds
def _inverse_filter(self):
# Remove elements from the original list if they should be present in the filtered list but aren't anymore (elements have been deleted from the filtered list).
# For all new elements in the filtered list, create a new element in the original list (elements have been created)
I tried all the tricks you mentioned with the same result...
The only workarounds (wich works!) I found is explained below:
1- You can use compute in ..._ids field definition
and put all the 'filtering stuff' in the def
but all lines on 'many' side will be read-only
(it's a problem for me because I need to edit these lines
2- You can define a new computed boolean field on the table wich is
on the "many" side (in your case 'mymodule.schedule_entry') and put
the 'filtering stuff' in the def. It works perfectly and the lines are editable !

How to get index of latest element in List Redis?

How to get index of latest element in List Redis?
For example in List is stored id's of messages, I need get last ID message and return index this element.
In Redis, the index -1 always refers to the last element in a LIST
This is a much better idea that trying to find the index from the start of the list (LLEN would be the way to get this), because if someone inserts or removes an item after you get the index but before you access the element, something's gonna break.
To get the last element of a Redis list, you can use the LINDEX key -1 command. You can also atomically remove the last element of a list with the LPOP key command.
Documentation for all of the Redis commands can be found at http://redis.io/commands.
To get the last element you can also use:
lrange mylist -1 -1

Use MVC to create multiple ids and names with the same name but incremented number at the end of name

I want to create multiple entities from a single form with parameters that have the same name. I'm trying to create an array starting with 1 and ending in the max number of items in the array. Does entity framework do this by default.
Example:
PersonName(1): "Bob"
PersonName(2): "John"
PersonName(3): "Mindy"
If I loop through collections using entity framework is there a preferred method for name and id attributes.
Html:
<input name="personname(1)" id="personname(1)" value="Bob" /><br />
<input name="personname(2)" id="personname(1)" value="John" /><br />
<input name="personname(3)" id="personname(1)" value="Mindy" /><br />
Also I noticed that when I use #Html.EditorFor it has some overloaded methods to name the id and name attributes. So would it be recommend to build these using the template name set to empty string, and the
htmlFieldName="personname" + "(" + i + ")";
Or is there a preferred technique?
If you use the Html helpers, it does this for you automatically, especially if you use the EditorTemplates. For example:
#for(int i=0, i<collection.Count; i++)
{
Html.TextBoxFor(m => m.collection[i].Name);
<input type="submit"/>
}
This creates the input elements with the proper indexing. The better way is to simply use editor templates though:
#Html.EditorFor(m => m.collection)
You can loop through the collection using for loop. Appending [index] to personname.
For example:
for(int i = 0; i < personName.Length; i++)
{
<input name="personName[" + i + "]" id="personName_" + i value=personName[i] />
}
Note, that ID value cannot contain brackets, braces or similar, that is why you need to use something like underscore plus index value.
The correct answer is you have to add the parent table as the Model. In every reference to any child fields or child tables's fields you have to refer to this parent model first. All child models must drill down in the EditorFor's HiddenFor's, TextBoxFor's etc... by calling on the parent model first. Without the parent it won't know how to correctly relate to it when its time to perform the save changes or when editing it needs to check the proper references. Both the parent ids and child ids must be listed out in order to combine all tables in a single form and then perform a save changes on the fields. Otherwise it won't include those fields or it will not be able to save that table correctly and not auto generate... yes I said "auto generate" the ids. If you try and auto generate the ids yourself it will make maintenance a nightmare.
There... I filled in all the information a noob will need to surpass the point farmers.
So why is this important? Because if the #Model does not point to the top most object that all other object are related to then it doesn't know how the reference relates. Example would be a Document table. But the Document table might have a foreign key to a Title table. That would be one to one. The Document table would still need to be listed first like so Document.Title.TitleName. In a one to many like in an Author... b/c there might be more than one Author.. you would still list Document first. As in Document.Authors ... author would be a collection so you would loop through each author. But at the very top even in Partials you would still only reference #modelDocument and not the author, that would be after the #Model portion in the content area. If you try and reference just the #model author portion. Now it doesn't understand how it relates to the document and you either have to add the document identifier inside the author table's foreign key for the documentid at some point later downstream after adding the author. This is unfortunate as its not necessary if you just started with the Document to begin with.
Of course this can get a little more complicated b/c you can have more than one document per author so a linking table to a documentauthors table would be preferable here... but still Document table would still be listed at the top of a partial view and even the main view in order to completely place the correct identifiers and names in an html page so that when the form is submitted it properly knows how everything is realted. Also the identifiers should be placed in the html helpers for hidden input fields if they are not to be displayed outwardly to the users.
Now to make it an incremented number of times and to start with a certain grouping... it would require a query string or a posting attributes to send the start and stop range for that group or list of authors, or list of books, or documents or whatever. Since the one to many and many to many relationships should be output in for loops, it can select the correct relationships to retrieve and select also the ones to be displayed using linq for the entity framework which is supplied in a private member variable that allow you to perform database crud ops.
For the point farmers... nothing.