I have a listbox which the items are linked to values stored in the registry. Is there anyway I can change the textbox's text depending on which item is selected in the listbox. I'll do my best on an example:
...............Item 1 Selected - Textbox text is 1 List Box - Item 2 Selected - Textbox text is 2
...............Item 3 Selected - Textbox text is 3
There are events with each control that can be used when something happens, an event. You will have an event for when the user changes the value of the list item. The simplist way to get to these events is just double-click the control and you will see that you are inside an event of that control. use the drop down lists at the top to change the type of event you are using.
Last edited by Grimfort; Jul 16th, 2006 at 05:54 PM.
Thank you. However, I am well aware of the events. The problem is that the items are user specified so I can't just say Listbox1.SelectedItem("TEXT") or whatever it is.
Also, the code you supplied in the screenshot doesn't work (for me). I'm getting this error: "Value of type 'String' cannot be converted to 'System.Windows.Forms.TextBox'. "
Last edited by TH3 K1D; Jul 16th, 2006 at 06:10 PM.
It doesnt matter what they are, my example picture included a tiny convert to a string object type command (its just example code). What exactly are you looking for, give some object examples.
You are probly saying this:
Text1 = dfdf not Text1.Text = dfdf
Something like that anyway. No such thing as default items in .net, unlike VB6.
Ok, thanks. This is a start. Now, for the hard part. Is it possible to have a string linked to the listbox item so like if you click 'Hello' the textbox says 'World'?
Private Function GiveMeMyText(ByVal UserInfo As String) As String
Select Case UserInfo
Case "Hello"
Return "World"
Case "3"
Return "Text 3)"
Case Else
Return "Unknown!!"
End Select
End Function
Thats a nice easy way if you are new to programming with objects. The other more usefull way is to use a collection. Now, there are various types of collections depending on version of .Net you are using.
Is it possible to do this with user specified strings that are in the ListBox? Thanks!
Again, its just data, as long as you can control some aspect of it, its no different from anything else. Of course you need to know what means what.
What are you comparing the "user" data to? A known list or another user specified list?
Ok, thanks again. The data is actually going to be stored in the registry so I don't guess I need to post it becuase I already know how to read/write to the registry and split strings.
I dont really need the actual data, I mean the format of your data, you still havent said what you are comparing. Is the text in the registry going to be tested against a known list (ie something you have hardcoded) or is it going to be some other data in the registry. If its hardcoded a simple select will probly work, but if its some other data you will need something like a collection.
No, it's not going to be hard coded. It's going to be strictly stored in the registry. I'm making a program where the user types in a product name, then the serial key and they save it to the registry so if they lose it, they can just open the application up and recover it.
EDIT:
I'm having trouble showing the serial after I save it to the registry. Do you have AIM or MSN so I can send you my project files and you can take a look?
2nd EDIT:
Is it possible to load up items in a ListBox from the registry?
Last edited by TH3 K1D; Jul 16th, 2006 at 06:47 PM.
You merely need to create a relationship between the data in the ListBox and the data you want to use. An easy way would be to use an implicit relationship, e.g.
VB Code:
Public Class Form1
Private names As ArrayList
Private birthDates As ArrayList
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.names = New ArrayList
Me.birthDates = New ArrayList
'Add the names and birth dates in the same order so that there is an implied relationship between the name and birth date at the same index.