Create a shared copy and paste menu for my grids - vb.net

I have 20 or so grids in my application suite. I'd like to create a global copy/paste context menu which I can bind to every single grid rather than code in each form.
I am unsure what is the best way to achieve this, I have started to create a class with my menu in it, but get stuck at the point of adding the actual menu options. For example I know I'll need to call a "copy" event, but I also know I'll need to tell it what I am copying, and I cannot see how that is done in vb.net when you can only add the address of a method minus parameters.
e.g.
.MenuItems.Add("Copy Cell", New System.EventHandler(AddressOf CopyCell))
Obviously I want "CopyCell" to only be coded in one place as well, rather than repeated in each form. I will always be copying the same object (SelectedCellCollection).
I am not sure how to make the menu have an event with parameters, or how to make it "know" that I want to always copy the selected items. I'm aware that I'd have to do some coding in the form but just trying to work out the way to minimize it.

I have created my own context menu class (via inheritance) with specific copy and paste functionality / options tailored to the grid I am using. It works fine and only needs one line of code per form/grid to activate.

Related

Trouble traversing Visual Tree in C++/WinRT

I'm implementing an app w/ Excel-style functionality where I have a ListBox of baskets, each containing a ListBox of Items, each containing a StackPanel-nested Button inside it.
XAML, What the layout looks like
Goal: I want to click on the button, such that the item entry (StackPanel) is highlighted via SelectedIndex(). I try to accomplish this in the GotFocus="ItemGotFocus" event handler, by traversing the visual tree to find the parent ListBox, so I can call SelectedIndex() on it.
However, I am getting errors whenever I call VisualTreeHelper::GetParent() or other functions from the namespapce in general:
Do I need to define a template definition somewhere, so it can figure out the type I want it to return, or is there a better way to go about this?
Thank you, it worked!
Turns out I had included <winrt/Microsoft.UI.Xaml.Media.h> in "pch.h", when what I really needed was <winrt/Windows.UI.Xaml.Media.h>.

How can i create a list to select from for a property on my user control?

I have a property on my user control called 'DataGridViewColumnType' and wondered if it was possible to make it a drop down and a list of column types to choose from? Even if it was just a list of strings would be good enough.
I have been playing with the attribute
<Editor("System.Windows.Forms.Design.DataGridColumnCollectionEditor, System.Design", GetType(UITypeEditor))>
But not having much luck and not sure it'd actually do what I want even if if I could get it to work. It just opens a column collection editor but the add button doesn't work and i haven't been able to get it to work so couldn't get any further.
So i thought if I can just create the list myself then somehow turn my property into a drop down that displays my list that would be fine. I just haven't done this before and can't seem to find much on how to achieve it.

MS access event load form

I have about 20 MS-Access databases with about 400 Forms and wish to perform an action whenever any form is loaded.
I would need, perhaps, an event at database or application level that would trigger at any form being opened/loaded. Then I might need only to add code once to each of the 20 databases, but not to each of the 400 forms.
And: it has to be in VBA (Access >= 2010)!
My Question: Is this even possible? And if so, does someone have a hint?
Thanks,
Pete
There are multiple ways to go about this, I think.
What I'd probably do is the following:
Create a hidden form that opens whenever your database opens (using an autoexec macro) with a timer.
When loading the hidden form, initialize a collection/multi-level array of all available forms in the database, and set their status to closed (somewhat difficult, probably would go with multilevel array or a collection inside a collection to be able to store form name + boolean open or closed).
Periodically iterate the collection, check for changes, so you can see whenever a form closes and trigger your event.
You could also use VBA to iterate through all the forms, add a module to them if there is none, and then add your desired Form_Load code to that module. (Would probably be wise to simultaneously create code to undo that action, so you can actually maintain the code). While refining that, you could check if the form already has a Form_Load action, and append code to that if it exists.
Alltogether, possible, but difficult. If you want pointers on some of the steps, I can give them, but for major issues on the implementation, I'd ask a separate question.

Add custom control to toolbox and have its properties show up in the properties window

To illustrate what I'm asking, let's say I have a custom TextBox that has 2 modes. Mode 1 only allows numbers, and mode 2 only allows dates in a particular format.
Using a class module I can create this custom TextBox, and I can use a loop when the userform initialises to set which TextBoxes are custom.
What I'd like to happen is have the custom TextBox, or what ever custom control I want, show up in the toolbox. And I also want its custom properties, if they exist, to show up in the property window.
So far, I've been unable to find a way to do this. In fact, I've been unable to find out if it's even possible. It seems, to me anyway, that it's something that should be possible, but maybe I'm barking up the wrong tree. If it's possible I'd really appreciate being pointed to a resource.

referring to different textboxes on each iteration

I'm making a Visual Basic program. I have a page where I want to be able to scale anywhere from 1 set of two textboxes and a label all the way up to 30. I'd really like to keep the display as simple as possible, So I'm trying to make buttons like add batch and remove batch that lets me adjust the boxes shown from 1 to 30.
I know that I can use a case statement or a if statement or even making a function that does one of those for me so I don't clutter up the main code, but that just seems so klunky. Any suggestions on a way that I can refer to one set at one time and another set at one time?
I ended up creating a class that and passed references ByRef to the class. Created methods of Show*( and Hide() that show and hide all objects that were passed to the class (just changing the Visible property)
Created one object of my new class for each batch set. Made an array with those objects in it, now I can call BatchGroups(3).Show() and iterate through my batches.
Still a bit of setup in my FormLoad event, but BatchGroup(txtBat1,txtBatQty1,lblBat1) and filling an array with those objects allows me to iterate through my batches whether I am adding, removing, adding 5 at a time, removing all but one... take your pick.
Could probably build an array with groupboxes as easily to refer to the whole group at once, but groupboxes would have looked somewhat tacky in this situation, I preferred to create my own object oriented groups.