here is my code:

 With RECEIPT
     For i = 0 To MENUORDER.lvorder.Items.Count - 1
       .LstOrder.Items.Add(MENUORDER.lvorder.Items(i)) 'dont know what to do next

     Next i
        .ReceiptNo.Text = Me.lblos.Text
        .lblTotal.Text = Me.lbltotal.Text
        .lblCash.Text = Me.TextBox1.Text
        .lblChange.Text = Me.lblchange.Text
        .ShowDialog()
  End With

[forms : RECEIPT, MENUORDER]

i dont know how to display listview subitems in the lisbox
i want to make a receipt thats why i want to transfer them..

Dani AI

Generated

As suggested, a ListBox is the wrong tool for multi‑column receipt data — use a DataGridView (or a ListView in Details view). , switching to a DataGridView will let you keep columns, numeric formatting and alignment, and it prints much more cleanly. If @Shark_1 pointed you in that direction, that was good advice.

Example: copy the ListView (MENUORDER.lvorder) into a DataGridView on the RECEIPT form. This routine creates matching columns and copies text and subitems while guarding against missing subitems:

' Call this on the RECEIPT form with MENUORDER.lvorder as the source
Public Sub PopulateFromListView(lv As ListView)
    DataGridView1.Columns.Clear()
    For i As Integer = 0 To lv.Columns.Count - 1
        DataGridView1.Columns.Add("col" & i.ToString(), lv.Columns(i).Text)
    Next

    DataGridView1.Rows.Clear()
    For Each lvi As ListViewItem In lv.Items
        Dim cells(lv.Columns.Count - 1) As String
        For c As Integer = 0 To lv.Columns.Count - 1
            If c = 0 Then
                cells(c) = lvi.Text
            ElseIf lvi.SubItems.Count > c Then
                cells(c) = lvi.SubItems(c).Text
            Else
                cells(c) = String.Empty
            End If
        Next
        DataGridView1.Rows.Add(cells)
    Next
End Sub

If you must keep a ListBox, build formatted strings (fixed-width) and use a monospace font so columns line up:

Dim line As String = String.Format("{0,-24}{1,6}{2,10}", itemText, qtyText, priceText)
LstOrder.Items.Add(line)
LstOrder.Font = New Font("Consolas", 9)

Troubleshooting notes: ensure MENUORDER.lvorder.View = View.Details so subitems exist; always check SubItems.Count before accessing; for money use Decimal.Parse and set DataGridView column DefaultCellStyle.Format = "C2" for currency. For printing, iterate the DataGridView rows in a PrintDocument.PrintPage handler and draw strings with e.Graphics.DrawString.

Recommended Answers

All 2 Replies

ListBox is not the appropriate for this purpose.
Anyone of Listview or DataGridView is best to show the receipt items.

@Shark_1, ahh, thank you, ill try to use DataGridView instead of listbox :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.