I have struggled to find a way to make this work. I have a listbox that has 5 items. These items are lets say Company Name, Address, User Name, Phone, Fax. On the form I also have the same labels with richtextboxes under each of the above names.
What I am looking to do is have each listbox item equal the text that is related to each textbox. Then write to file from the listbox.The file created should be the text from the related textboxes.
The goal is to allow the user to re-arrange the items in the listbox via drag and drop (which I think I have figured out) and write a new order of the file.
Here is my code Code:
Private Sub listBoxCompInfo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listBoxCompInfo.SelectedIndexChanged
Thank you for your response. I feel like such an idiot. I did make the change and it does change the listbox item to the text that was input from the textbox. What I was looking for is too not have the listbox item text change but rather make an association to the listbox item and the textbox. Maybe I am going about this all wrong or using the wrong controls. How can I make a listbox item retrieve the string in text box without changing either the listbox item text or the textbox text.
The textboxes are to be input fields for the user to enter information. The listbox items need to be connected to the correct textbox somehow in order for the user to re-arrange the entered information in the listbox. When the user clicks a button that information will be written to the file. As it sits right now only the contents are being written to the file and not the textbox information.
Using drag and drop. The user can change the order at runtime. Here is the code I have. Seems to have a small bug as the listbox items move but on the drop event become invisible.
Code Code:
Private Sub listBoxCompInfo_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles listBoxCompInfo.DragDrop
Bingo!!!! Paul you are the man!!! This is exactly what I was looking for. Thank you so much. You are might be the listbox king! Thanks again man for all the help I REALLY appreciated it and the example you shared is going to push my knowledge base a ton.
I noticed that this is on the form load event. The controls are in tabpage so can I assume that I can use the tabpage click event instead of form1 load? Or would it be more efficient to create a usercontrol then initiate that component.
That is what I thought. But I am having difficulties initiated the 2 control. The first one works perfect but am not quite sure how to get the second one to initiate.
Code for Custom Tabpage Class Code:
Public Class TabPageEx
Inherits System.Windows.Forms.TabPage
Private WithEvents uc As New UserControl1
Private WithEvents uc2 As New UserControl2
Public Sub New()
Me.uc.Margin = New Padding(0)
Me.uc.Dock = DockStyle.Fill
Me.Controls.Add(Me.uc)
Me.UseVisualStyleBackColor = True
Me.uc2.Margin = New Padding(0)
Me.uc2.Dock = DockStyle.Fill
Me.Controls.Add(Me.uc2)
Me.UseVisualStyleBackColor = True
End Sub
Private Sub InitializeComponent()
End Sub
End Class
Here is the button click event that adds the tabpage.
Code Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Mytab As New TabPageEx
frmPrefsDialog.TabControl1.TabPages.Add(Mytab)
Mytab.Text = RichTextBox1.Text
frmPrefsDialog.TabControl1.SelectedTab = Mytab
Me.Close()
End Sub
Now I am struggle on how to inititiate the second usercontrol still using the TabPageEx Class. Do I need to make another seperate Class Such as TabpageEx2 too handle usercontrol2? The usercontrol2 needs to happen on form load so that the tab is always present. This may be a simply answer and apologize. I truly am trying to learn this at times gets so confusing.
I realized that this should be another topic. Mod please mark this as resolved