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:
  1. Private Sub listBoxCompInfo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listBoxCompInfo.SelectedIndexChanged
  2.  
  3.         listBoxCompInfo.SelectedItem(0) = rtbCompName.Text
  4.         listBoxCompInfo.SelectedItem(1) = rtbCompAddr1.Text
  5.         listBoxCompInfo.SelectedItem(1) = rtbCompAddr2.Text
  6.         listBoxCompInfo.SelectedItem(2) = rtbProgrammer.Text
  7.         listBoxCompInfo.SelectedItem(3) = rtbPartNumer.Text
  8.         listBoxCompInfo.SelectedItem(4) = rtbMachineName.Text
  9.         listBoxCompInfo.SelectedItem(5) = rtbComments.Text
  10. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveSettngs.Click
  11.         Dim ItemArray(Me.listBoxCompInfo.Items.Count - 1) As Object
  12.         Me.listBoxCompInfo.Items.CopyTo(ItemArray, 0)
  13.         Dim Data As String = Join(ItemArray, Environment.NewLine)
  14.         My.Computer.FileSystem.WriteAllText("c:\test.txt", Data, False)
  15.     End Sub

Any Help would be greatly appreciated!