Visual Basic 2010 - Referencing objects in different user controls - vb.net

For an app that uses user controls instead of forms and the first user control has a listview, where the user clicks or selects "Create New" Or Delete, what is the best way to transfer the data selected in the listview to the detail screen (separate User Control) where the data can be edited?
Can I just reference the list view in the first UC in the Details UC? something like:
ucHeader.lvSetups.FocusedItem.SubItems.Count = 0
from the ucDetail user control?

Saying which way is the best would produce a heated discussion with every ones opinion. However, here are a few ways I would tackle this. While there are more options, these are what I would do:
You should expose any information you want to read from a user control in the form of a property, readonly if you must. Just an example because I don't know what your object types are:
Public ReadOnly Property SelectedItem as object
get
Return Listview1.SelectedValue
end get
End Property
You can also use events to tell the parent of your user control that a selection was made. You can pass whatever you want in this event, even the selected object. If you don't want to pass the selected object, grab it from the property you created (like #1) in the event handler.

Related

restricting a combobox to list values and outdated list values

I am creating a program that for simplicity's sake records the name of a staff member that receives a phone call. This program is designed to show old entries along with creating new ones.
The problem is that I want a user to only be able to select a listed name from the drop box when creating a new entry. But this list will only show current employees. Yet, when viewing older calls this combobox field also needs to display former employees that took a call that may no longer be in this list.
As far as I can tell with the Microsoft control and properties there is only 2 options that relate to this matter.
DropDownStyle as DropDown or DropDownList.
When using DropDown the user can submit any name (which is not wanted).
With DropDownList the user can only submit names on the list, but when browsing through old entries any names that are no longer on that list will not appear on their respective calls (which is also not wanted).
I'm aware I could end up having to implement my own combobox class but I wanted to see if anyone knew of a more elegant fix that combined both of these functionalities. Thanks!
It seems to me you have two modes. Add mode adds a new call record, while view mode displays old records.
Use the drop down list to restrict the user to what you load. When in Add mode, load the control with only current employees. When the form is in view mode, load with all employees.
Use DropDown. In the Validating event, set e.Cancel = True and instruct an ErrorProvider control to put up a warning with its SetError method if SelectedItem Is Nothing, but clear the error (by passing Nothing to SetError) otherwise. Then, in the combo box's SelectionChangeCommitted event, call the form's Validate method.

How to create click event for dynamically created custom control?

Let say that I'm creating thousands of custom controls, each control has own data assigned to it (like name, id, etc.), now I would like to add
click event for each of these custom controls
access from software any of these dynamically created controls
So I would like to show MsgBox if user click control #452, which will be returning values assigned to object in custom control class (passed during creation of new control on user form)
Second thing is that I would like to access at any time any of these objects and read values assigned to object in control....
How to do it ? Each control has name assigned like "Example1", "Example2", "Example3" but I don't know how to access it from code as any of these exists during writing...
Also I were trying to find how to create and rise events but it seems that all solutions are for statically created controls and I need to rise events for dynamically crated custom controls....
Thanks in advance for any tips/help how to solve it.
I'm using VB.NET
Ok I figured it out !
It is very simple actually.
If any one will be looking for an answer :
To access dynamically created control first we are going to name it :
Dim Control as new CustomControl
Control.Name = "Name" & Counter
Next after we've created new controls we are going to access it using:
Dim _Control as new CustomControl
_Control = Ctype(Me.Panel1.Controls("Name1"), CustomControl)
MsgBox(_Control.Name.ToString)
Viola
I still not sure about custom events for all controls on custom control (so where ever user click, there should be override event which returns something back, now I can only either click panel container (not labels/pictureboxes) from code inside user class, or event per control on custom control (but issue is that I want to pass data from custom control to user class).

VB.net User Control Issues

I've created one user control which have textBox & DatabGridView etc. When any user start typing in textbox then the filter is applied in DatabGridView. Now I want to add following features in this control how can I add these?
I want to use same control for supplier, customer, vendors on a single form, so I've placed it 3 times from toolbar. But for each control I want to fill different data from database. So what will be the best way to bind the control?
As we knew each table (customer,supplier & vendor) can have different columns, so I also need properties to set them. I've added property to my control but how can I ensure user has assign value in it? I.e. if user run the form and X property is not assigned to control then it should show message.
Note: I've tried it on control load event but didn't get any success because control's load event is occurred prior to form load and I'm assigning property on form load.
Please help....

Interaction between custom forms and event receivers

How can we interact with custom forms and event receivers? How can we talk to custom fields (asp controls) within the custom form from an event recievers?
I searched but cant find something like that or maybe I am not using the right keywords.
In the event receiver you do not have access to any of the controls on a form. What you do have is access to the SPItemEventProperties object which has the BeforeProperties and AfterProperties, er... properties. These are hashtables which contain the names of the SPListItem's fields and their corresponding values (from the form or from the existing item). You can use the event receiver to inspect these values and take a particular action, or even cancel the event.

How do I create a "wizard" style ui using vb.net?

The idea is that I would have a set of forms, users would click through a "forward" and "back" button, and the current form would change to a different one. My issue is that I can write code that just pops up a new form, but im not sure how to do a "replacement" of my current form. How is this usually done?
What I did recently was to create a form with buttons already in place and a large panel to contain each step. The dialog would accept an initial step in the form of a IWizStep instance, and the things would roll from there.
Each step was a class exposing a UserControl responsible for the visual aspect of the step, while the logic itself was handled by the class (it was a little more complicated that that, but that was the general idea).
The IWizStep interface, implemented by the step and accepted by the dialog, was on the lines of:
Interface IWizStep
Event StateChanged As EventHandler
ReadOnly Property Control As Control
ReadOnly Property Title As String
ReadOnly Property CanMovePrevious As Boolean
ReadOnly Property CanMoveNext As Boolean
Function MovePrevious As IWizStep
Function MoveNext As IWizStep
End Interface
To put everything together, a controller class would know how to compose the steps necessary for each given action. Therefore I had a controller for, say, "Emit Order", which needed some 10 steps, and a controller for "Emit Orders in Batch", which needed only a couple of steps.
Create a set of UserControls, and add and remove them from a Panel in a single form. (and set Dock to Fill)
You could define a user control which acts as a "wizard". It just needs the buttons you have and an array of content panels, just have it switch through the panels when the buttons are pressed assuming a certain condition is met within the controls on the panel. There's no real definitive "wizard" maker, since it's pretty easy to roll your own wizard.
You don't need to do a "replacement" of your current form really, you could just add a new one to the project. If you do need to for whatever reason, just grab the control collection with Me.Controls, copy that somewhere, and put the new controls up. When you don't need the wizard, swap them out again. It's generally best practice to make a new form however!