i have a rich text box that displays items.These items have column names.The column names are loaded when the form loads.They hold values as rows.These rows are appended at a click of a button (when add button is clicked).

At the bottom,let me say i have another field(total amount) in the rtb which displays total value of a Amount column.This is also displayed when calculate button is clicked.

If someone wants to add another row to be calculated it would create the format displayed.so i wanted to clear the total amount field when another item gets added.Is there a way to do that.

It sounds like you're making it more complicated than it needs to be. A ListView was designed for this type of data. Set the View property to details and set the columns up. Now each row belongs to separate item.

If you must insist on using a rtb the Lines property is an array of the lines of text in the rtb

I changed the RTB to listview control.I used this code to add the items to the list view but argument out of range exception came.Can you see the problem
?

Public Sub AddList(ByVal payItem As Double, ByVal subpayItem As Double, ByVal subItem As String, _
        ByVal unit As String, ByVal bridgeType As String, ByVal span As String, ByVal quantity As Double, _
        ByVal rate As Double, ByVal amount As Double)
        With ListView1.Items.Add(ListView1.Items.Item(0))
            .Text = payItem
            .SubItems(1).Text = subpayItem
            .SubItems(2).Text = subItem
            .SubItems(3).Text = unit
            .SubItems(4).Text = bridgeType
            .SubItems(5).Text = span
            .SubItems(6).Text = quantity
            .SubItems(7).Text = rate
            .SubItems(8).Text = amount
        End With
    End Sub

Yopu can't add a listview item to the same collection like that. Also your programming with Option Strict Off. Implicitly converting number to string is a sloppy bad habit that will screrw you up royally when you get on to larger more involved projects.

See if something like this works better:

Public Sub AddList(ByVal payItem As Double, _
                   ByVal subpayItem As Double, _
                   ByVal subItem As String, _
                   ByVal unit As String, _
                   ByVal bridgeType As String, _
                   ByVal span As String, _
                   ByVal quantity As Double, _
                   ByVal rate As Double, _
                   ByVal amount As Double)
    ListView1.Items.Add(payItem.ToString()).SubItems.AddRange( _
    {subpayItem.ToString(), _
     subItem, _
     unit, _
     bridgeType, _
     span, _
     quantity.ToString(), _
     rate.ToString(), _
     amount.ToString() _
     })
End Sub

It worked well thank you,but how can i align the "Total Amount" and the total value to the right of the listview? 27c618d5847ec8d9c7701f47cd981841

Add a new item with all the fields as space except for the ones you want to have values.

 ListView1.Items.Add(" ").SubItems.AddRange( _
{" ", _
" ", _
" ", _
" ", _
" ", _
"Total Amount", _
" ", _
totalvalue.ToString() _
})

If you use groups you can add more items and increment the total without rebuild the whole listview.

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.