Item sorting based on skills

So what I have is essentially a Window_BattleItem (this window is exactly the same as the regular battleitem window except that it doesn't display the help text for items in it) displayed under the skill window in battles. What I would like to do is have the items in my Window_BattleItem to be listed in exactly the same order as the skills listed (as the skills use up an item of the same name when used). Also the skills do not get listed unless the player has at least one of the item that it uses.

Any help would be appreciated. (Also let me know if you need any extra information).
I believe that (by default) Items show up ordered by ID, just like Skills do, so all you'd need to do is arrange the appropriate Items in your database in the same order that the corresponding Skills are ordered.

If these would be infeasible due to some massive amount of hard-coded values that you've added into the system, it is possible to sort items before loading them to the window.  You'd have to create some kind of script that would associate a DataBase Item to a DB Skill and then basically say "sort these Items by the Name of the corresponding DB Skill, then draw them to the Window".  Definitely feasible, but only worth it if it would take several hours to re-order the Items in your database.
Yea the reordering is rather infeasible due to how you gain items (I would have to change about 50+ events and like 300 values for variables with the possibility that I might miss some).

I was thinking on the lines of a for loop, with an if statement nested inside asking if the item name equals the skill name. Then to have it push the item into the item list. I am not quite certain if this would be the correct or even the easiest way. (Now that I am thinking of it I am coming up with a scenario where the item name doesn't equal the skill name and it would just skip that one).

Original thread: https://forums.rpgmakerweb.com/threads/item-sorting-based-on-skills.37260/