Access Dynamic Controls from another functions - vb.net

Private Sub btn_addNew_member_Click(sender As Object, e As EventArgs) Handles btn_addNew_member.Click
Dim myTabPage As New TabPage()
As this bottom clicked I created the controls by writing codes and setting locations and sizes. These controls are only created when the AddMember is clicked. After that , user will input the values in that tab pages,
error when try to get a control from another sub
Private Sub Resettt(sender As Object, e As EventArgs)
full_box.Clear() ' full box is added in myTabPage and cannot access
End Sub
I add a dynamic tab page which also add many controls dynamically. I learned about how to handle the events of these dynamic controls by using "Add Handler" and "Remove Handler" and it worked well. But I also need to access the controls itself like the text from text boxes, selected indexes from combos by outside functions. But as they are built dynamic , I cannot access. I do research a lot but I still don't know how to solve it.

Related

How can I filter a ListView using TextBox and ComboBox?

Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
ListView2.Items.Clear()
Dim curSelectionCombobox As String = ComboBox2.SelectedItem.ToString()
ListView2.Items.Add(listitm)
End Sub
Well basically this is what ive come up with the filtering thing in combobox which is obviously wont work
and in the combobox and button i didnt get to try coding those but im quite sure it wont work either im new in this language and im struggling to catch up giving the fact that this pandemic really gets me more and more stupider as the day passed by
Well my main problem is that the filtering in the groupBox_bookShelf is when i choose a genre in the combobox the static listview will filter leaving only the exact items its genre selected in the combobox
the second is the combobox and button im aiming to link the action of both property when filing in the groupBox_bookInformation then once the filter button is clicked i want to filter the lower listview leaving only the selected genre and its items
Here is the sample form ive been working on.
enter image description here
I am guessing that what is selected in the combo box is a value that appears in some of your list view items.
Start by calling .BeginUpdate() This will prevent the user interface from repainting on each update which would really slow things down.
I loop through the items and test one of the sub items to see if it matches the combo selection. If it does not match is is removed.
Be sure to call .EndUpdate or the changes will not show up.
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim curSelectionCombobox As String = ComboBox2.SelectedItem.ToString()
ListView2.BeginUpdate()
For Each lvi As ListViewItem In ListView2.Items
If lvi.SubItems(6).Text <> curSelectionCombobox Then
lvi.Remove()
End If
Next
ListView2.EndUpdate()
End Sub

VB 2013 Persistent User Settings

On my form I have a menu with "file-save". When I click save I want to save particular settings to restore when the form is closed and re-opened. I've done this successfully for text in text-boxes and the checked states of check-boxes, but I'm failing when trying to loop through the items in a list-box. Please see below for what I've tried...
When I click save:
Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles SaveToolStripMenuItem.Click
For Each i In ListBox1.Items()
My.Settings.ListBox1.Add(i)
Next
My.Settings.Save()
End Sub
When my form loads:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
For Each i In My.Settings.ListBox1()
ListBox1.Items.Add(i)
Next
End Sub
I've only been using VB for three days, so apologies if I am missing something simple ha! Thanks for any help!!!
There is one small glitch with the StringCollection in settings. If you do not seed it with a fake variable then it starts out as Nothing and you cannot add to Nothing. in your form load add this:
' if the collection has not been initialized, do so
If My.Settings.ListBox1 Is Nothing Then
My.Settings.ListBox1= New System.Collections.Specialized.StringCollection
End If
' now it is safe to use: load strings from Setting -> form listbox
For Each s As String In My.Settings.ListBox1()
ListBox1.Items.Add(s)
Next
The very first time it runs, there are likely no saved settings, so we have to create the container for them, basically.
Option Strict can be implemented by file, by adding this at the top:
Option Strict On
Or for the project: Project => Properties => Compile: Option Strict is likely to the right (I have 2012). You can also set it as a permanent option (recommended).
Among other things, this will prevent you from plucking variables out of the air and use them without declaring a type (which will lead to errors). For instance:
For Each i In My.Settings.ListBox1()
becomes
For Each s As String In My.Settings.ListBox1() ' tell the compiler the Type

How can you make new form as a copy (in runtime) of an already shown form?

I am trying to make a form that functions as "READ/OPEN MAIL".. so what I want is to have multiple forms (which is a copy, with both the designer and form functions e.g. buttons and codes) when I open multiple mails.
I know how to create a new window but I do not know how to copy the designer codes and functions from anoher form and apply it to the newly created form. I have searched google but it only directs me to different questions. Thanks in advance!
All you have to do is create a variable of the type of your class, then show it using the Show method.
i.e.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim myform As Form1 = New Form1
myform.Show()
End Sub

Making specific text a hyperlink

is it possible to have specific text in a listbox line to act like a hyperlink?
dim sLocation as string = "\\server\folder\subfolder\"
LstOut.Items.Add("text text text" & sLocation)
I would like this to open in explorer.
This is not an ASP application, just a plain old winform.
I googled you question and on Tek-Tips Forums it says:
I would create a datatable that
contains the hyperlink text, and the
actualy HREF. catch the onclick event
of the list box, grab the record they
clicked, and use
system.diagnostics.process.start(HREF)
to open the default browser to the
link.
One suggestion would be to monitor when the listbox's index is changed. When it's changed, check to see if the index you're looking at is the one that ultimately needs to open up explorer. You could use a process.start command to open up explorer. I'm thinking something along the lines of
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
if (listBox1.selectedIndex = indexToLookFor) Then
Process.start("explorer.exe", File_Path)
End If
End sub
Now, if you wanted to have the text from the selected item act as a local link to another folder on the system, it would simply be a matter of using this call instead
process.start("explorer.exe", listbox1.text)

Dynamic dropdown based on Radio selection

Good morning all! Myself and a co-worker are tasked with a system-wide scripting solution but neither of us are .NET programmers so we need your help.
We have a GUI that displays a radio selection box (3 options) that are the three sites where our hospitals are. We need to dropdown located on the form to fill with only the locations based on the selected radio option.
my gui http://web6.twitpic.com/img/40330741-85d91a5637f2445b322e62df17cf3351.4aef01c5-full.jpg
Here is the code behind we have so far (sorry, VB)
Public Class frmCEHLI
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CELocDataSet.dbo_Locations' table. You can move, or remove it, as needed.
Me.Dbo_LocationsTableAdapter.Fill(Me.CELocDataSet.dbo_Locations)
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
MsgBox("Submit button has been pressed")
End Sub
End Class
For the record the Location dropdown is currently databound but its a static SELECT statement which brings us all the locations but we'd prefer it to be cleaner if it only returned the locations based on Site. We are using Visual Basic 2008 Express Edition for development. Any help/code is appreciated, thanks!
Sorry not to respond back sooner, busy, and wanted to dig up a sample that did just what you were needing.
Create two comboboxes on your form. You can bind either fixed values, or from a table on the first combo. Then, from the property/events sheet, first set the "AutoPostBack" to TRUE, then on the events, click for the "SelectedIndexChanged" event to bring up some code.
The "Sender" object parameter will be the combobox itself, so you'll be able to analyse the property settings via debugging to find what key/value was chosen.
Then, run whatever query from your data querying control, business object, or whatever that gets your results, such as to a DataSet or DataTable.
Finally, set the datasource of your second combo to the above result query, set dataTextField and DataValueField and issue DataBind() to the combo.
That should get exactly what you need.
Then, when someone makes a selection from the second combo, you can have code within ITS "SelectedIndexChanged" event (also based on its AutoPostBack or actual submit button on the form).
Hope this helps.
I would create two combobox controls... One for the "where", then, on the InteractiveChange event by the user to post-back to the page using that answer for the second combobox of locations based on the "where" value of the first combo.