none
Listbox Data to RichTextBox (Newb)

    Question

  •  

    Hello All,

     

    I am writing a program to contain notes for work being done. I am writing this in Visual Basic 2008 express.

     

    One of the things I have is a Usercontrol with textboxs and a Form with a Listbox to contain the data that the user enters.

    I have another form with a Rich Text Box that I want the data to be printed to.

     

    The problem I am having is I cannot find a way to get the data out of the list box and into the Rich Text Box so they can copy and paste the results into whatever they need to.

     

     

     

    Here is the Code that I have for my Usercontrol

     

    Code Snippet

    Public Class PINx

    Private _PIN As String

    Private _IMEI As String

    Private _IMSI As String

    Private _Mobile As String

    Private _BBOS As String

    Private _DevType As String

     

    Public Sub New()

    Me.New("", "", "", "", "", "")

    End Sub

     

    Public Sub New(ByVal PIN As String, ByVal IMEI As String, ByVal IMSI As String, ByVal Mobile As String, ByVal BBOS As String, ByVal DevType As String)

     

    _PIN = PIN

    _IMEI = IMEI

    _IMSI = IMSI

    _Mobile = Mobile

    _BBOS = BBOS

    _DevType = DevType

     

    End Sub

     

    Public Property PIN() As String

    Get

    Return _PIN

    End Get

     

    Set(ByVal value As String)

    _PIN = value

    End Set

    End Property

     

    Public Property IMEI() As String

    Get

    Return _IMEI

    End Get

     

    Set(ByVal value As String)

    _IMEI = value

    End Set

    End Property

     

    Public Property IMSI() As String

    Get

    Return _IMSI

    End Get

     

    Set(ByVal value As String)

    _IMSI = value

    End Set

    End Property

     

    Public Property Mobile() As String

    Get

    Return _Mobile

    End Get

     

    Set(ByVal value As String)

    _Mobile = value

    End Set

    End Property

     

    Public Property BBOS() As String

    Get

    Return _BBOS

    End Get

     

    Set(ByVal value As String)

    _BBOS = value

    End Set

    End Property

     

    Public Property DeviceType() As String

    Get

    Return _DevType

    End Get

     

    Set(ByVal value As String)

    _DevType = value

    End Set

    End Property

     

    Public Overrides Function ToString() As String

    Return String.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}", PIN, vbNewLine, IMEI, IMSI, Mobile, BBOS, DeviceType)

    End Function

    End Class

     

     

    and

    Code Snippet

    Public Class PINControl

    Public Function GetPIN() As PINx

    Return New PINx(tbPIN.Text, tbIMEI.Text, tbIMSI.Text, tbMobile.Text, tbBBOS.Text, tbDevType.Text)

    End Function

     

    Public Sub SetPIN(ByVal pin As PINx)

    tbPIN.Text = pin.PIN

    tbIMEI.Text = pin.IMEI

    tbIMSI.Text = pin.IMSI

    tbBBOS.Text = pin.BBOS

    tbMobile.Text = pin.Mobile

    tbDevType.Text = pin.DeviceType

    End Sub

     

    End Class

     

     

     

     

    Here is the snipet for the code on my main form:

     

    Code Snippet

    Private Sub cmd2ADD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd2ADD.Click

    PINList.Items.Add(PinControl1.GetPIN())

    End Sub

     

    Private Sub CMDRem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CMDRem.Click

    Dim index As Integer = PINList.SelectedIndex

    If index >= 0 Then

    PINList.Items.RemoveAt(index)

    PINList.SelectedIndex = Math.Max(0, index - 1)

    End If

    End Sub

    Private Sub cmdEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEdit.Click

    If PINList.SelectedItem >= "" Then

    PINList.Items(PINList.SelectedIndex) = PinControl1.GetPIN()

    End If

    End Sub

    Private Sub PINList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PINList.SelectedIndexChanged

    Dim index As String = PINList.SelectedIndex

    If index >= 0 Then

    Dim pin As PINx = DirectCast(PINList.SelectedItem, PINx)

    PinControl1.SetPIN(pin)

    End If

    End Sub

     

     

     

    This works great for inputting the data

    I have no clue how to make the Listbox (PINList) print the data to a new rich text box form I have made.

     

    Any ideas??

     


    Thanks in Advanced

    Wednesday, April 23, 2008 3:18 PM

Answers

  • I am not sure if I understand completely, but I will give it a shot.

     

    To answer this I created a form with a list box, button, and rich textbox. When the form loads I add 4 items to the list and then when the button is pressed those 4 items are transferred to the rich textbox:

     

    Code Snippet

    Public Class Form1

     

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    ListBox1.Items.Add("Test")

    ListBox1.Items.Add("Test1")

    ListBox1.Items.Add("Test2")

    ListBox1.Items.Add("Test3")

    End Sub

     

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim x As Integer

    For Each item In ListBox1.Items

    RichTextBox1.Text = RichTextBox1.Text & ListBox1.Items(x) & Environment.NewLine

    x += 1

    Next

    End Sub

     

    End Class

     

     

    This gets each item out of the listbox array and puts it in the rich texbox. 

     

     

    Hope I understand correctly,

    Runrin

    Wednesday, April 23, 2008 5:54 PM