Making specific text a hyperlink - vb.net

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)

Related

VB.NET Check for keydown on dragdrop

I've tried searching quite a bit for this answer but haven't been able to find a good solution.
I have a datagridview on my form where users can drag and drop files onto the grid and certain columns are filled in. This works fine.
I want to be able to check if a user has a certain key pressed at the time the file is dropped. If so, I want to use that to add specific data to one of the columns in the datagrid.
Is this possible?
EDIT:
I have used keydown outside of dragdrop before but it seems that I'm missing something. The code I have is below. No matter what I do, I never get "T is pressed" but I always get "T is not pressed".
Private Sub frmReader_DragDrop(sender As Object, e As DragEventArgs) Handles Me.DragDrop
Dim files As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
If Keyboard.IsKeyDown(Keys.T) Then
MsgBox("T is pressed.")
' Put certain info into the datagridview
Else
MsgBox("T is not pressed.")
' Put other data into the datagridview
End If
End Sub
God, embarassing... I changed "Keys.T" to "Key.T" and it's working fine. Sorry for the bother.

Access Dynamic Controls from another functions

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.

Howto automatically load text from txt file to vb.net

I have a small program I use to launch applications (Visual Studios), I would like to add a Label that would (AUTOMATICALLY) display a message from a text.txt file once the application is load (NO BUTTONS). I will have about 10 of these small apps so this would make it easier to update in the future.I am new to program.
If you double-click your Form window in Visual Studio, you will create an event handler function called FormName_Loaded or similar. This function will be automatically called (no buttons required) when the form finishes loading.
In this function, you can set the value of your label text. For example, if your label is called lblFileData, you can put in:
lblFileData.Text = System.IO.File.ReadAllText("path\to\file\text.txt")
This loads all text from the file and assigns the text to the label. Just make sure that the label size and max length are sufficient to show all the text in the file.
You can write this
Label1.Text = My.Computer.FileSystem.ReadAllText("C:\Test.txt")
What metacubed suggested should work. Assuming the label was added through the designer. The code behind should look like this:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Label1.Text = IO.File.ReadAllText("C:\testFile.txt")
Catch ex As Exception
HandleException(ex)
End Try
End Sub
Helpful tip, you should always use a Try/Catch block when reading from files. Otherwise if an exception occurs, your application will crash and that's not user friendly. The "HandleException()" is just a method I made up that can do certain actions when exceptions occur such as displaying the text "Unable to read from file." on the Label1.

How can I keep items in ComboBox after close the application

Public Class Form1
Private Sub btnAddCat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddCat.Click
If txtAdd.Text <> "" Then
comboBox1.Items.Add(txtAdd.Text)
txtAdd.Clear()
Else
MessageBox.Show("Fill the blanket")
End If
End Sub
End Class
If user close application should see the items but there is no items
Can anyone help?
thanks
If you want the application to remember the value the next time it is run, you will need to save the value to disk. There are many different options for how to do that (e.g. text file, XML, database, registry), but for simple tasks, I'd recommend just using the built-in Settings feature.
To use the Settings feature, first you need to open your project properties screen. Then select the Settings tab. Add a new setting by typing in the name and selecting a data type. For instance, you could type MyItems for the name, and then select System.Collections.Specialized.StringCollection as the data type. Then, in your code, you can read the current value of the setting like this (perhaps in your form's Load event handler):
For Each i As String In My.Settings.MyItems
ComboBox1.Items.Add(i)
Next
And then you could save the list to the setting, like this (perhaps in your form's FormClosed event handler):
My.Settings.MyItems.Clear()
For Each i As String In ComboBox1.Items
My.Settings.MyItems.Add(i)
Next
You need to persist the data to a data store (either the database or the file system) so that the next time the application runs, then it can check the data store and display the items to the user.

Vb.net + AutoComplete in textboxes

So I was reading a bit on AutoComplete of textboxes in VB.NET, but I can't really understand where these are stored? Is it a fully built in feature, or do I have to write some code for it to work? I've found the AutoCompleteMode and AutoCompleteSource properties of textboxes. But I want to append whatever I've written in the textbox to the autocomplete source. Do I connect the source to My.Settings or something? Wouldn't I have to use an array as well? Any help would be appreciated :)
You would have to add new entries to your auto-complete data source manually... which makes sense, when you think about it: How is Windows Forms supposed to know when a new entry should be added to the list of suggestions and when the text entered is only something temporary?
You could add new values e.g. when validation of the input field happens, or when the user presses an OK / Apply button, or whatever fits your need best. But you will have to do this yourself.
The properties you've already discovered are the right ones.
Dim suggestions As New List(Of String)
suggestions.Add("Abba")
suggestions.Add("Nirvana")
suggestions.Add("Rolling Stones")
...
textBox.AutoCompleteSource = suggestions
You can bind AutoCompleteSource to almost anything; this is very similar to data-binding. One thing to keep in mind is that if you're adding new entries to the auto-complete data source, the UI control might not immediately notice if your data source doesn't implement the INotifyCollectionChanged interface.
first create the list to use as the custom source.
Dim MySource As New AutoCompleteStringCollection()
and then set the property of the textbox
With MyTextbox
.AutoCompleteCustomSource = MySource
.AutoCompleteMode = AutoCompleteMode.SuggestAppend
.AutoCompleteSource = AutoCompleteSource.CustomSource
End With
put this code in eventlistener you use for validating the input field, e.g. btnOK.Click
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
MySource.Add(txtinput.text)
End Sub