listview display  
Author Message
syndicate





PostPosted: Visual Basic Express Edition, listview display Top

hi.. can anyone help me to add a part of code wherein i can sum up the total debit, and display it to a cell in the listview just 2 spaces below the last read debit amount. i just can't do it.. this code works in displaying the data in listview coming from the database.

but how can i add data in the listview just after i read the database..i want to add the total debit amount on the 3rd column, 2 spaces below the last row of debit column.. please help me.

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

lv.ListView1.View = View.Details

lv.ListView1.ForeColor = Color.Navy

Dim myCommand As New OleDb.OleDbCommand()

Dim myConnectionString As String = ""

' If the connection string is null, use a default.

If myConnectionString = "" Then

myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\hazel\My Documents\Test.mdb;"

End If

Dim myConnection As New OleDb.OleDbConnection(myConnectionString)

lv.ListView1.GridLines = True

myCommand.Connection = myConnection

myConnection.Open()

myCommand.CommandText = "Select Name, CodeDesc, Debit from AllTransaction"

Dim reader As Data.OleDb.OleDbDataReader

reader = myCommand.ExecuteReader

'This sets the columns of the ListView to the same column names of the table in the database

With lv.ListView1

.Columns.Add(reader.GetName(0), 80, HorizontalAlignment.Center)

.Columns.Add(reader.GetName(1), 80, HorizontalAlignment.Center)

.Columns.Add(reader.GetName(2), 80, HorizontalAlignment.Center)

End With

'Now scrolling through the DataReader and populating the ListView with the data

While reader.Read

Dim ls As New ListViewItem(reader.Item("Name").ToString()) ' you can also use

ls.SubItems.Add(reader.Item("CodeDesc").ToString())

ls.SubItems.Add(reader.Item("Debit").ToString())

lv.ListView1.Items.Add(ls)

End While

lv.ListView1.Items.Add("")

lv.ListView1.Items.Add("")

lv.ListView1.Items.Add("Total")

myConnection.Close()

Me.Hide()

lv.Show()

End Sub

End Class




Visual Studio Express Editions38  
 
 
DMan1





PostPosted: Visual Basic Express Edition, listview display Top

Dim TheTotal as Integer =0

Dim ls as ListViewItem

While reader.Read

ls = New ListViewItem(reader.Item("Name").ToString()) ' you can also use

ls.SubItems.Add(reader.Item("CodeDesc").ToString())

ls.SubItems.Add(reader.Item("Debit").ToString())

TheTotal = TheTotal + Cint(reader.Item("Debit"))

lv.ListView1.Items.Add(ls)

End While

myConnection.Close()

lv.ListView1.Items.Add("")

lv.ListView1.Items.Add("")

ls = lv.ListView1.Items.Add("Total")

ls.SubItems.Add(" ")

ls.SubItems.Add(TheTotal)



 
 
syndicate





PostPosted: Visual Basic Express Edition, listview display Top

Dim TheTotal as Integer =0

Dim ls as ListViewItem

While reader.Read

ls = New ListViewItem(reader.Item("Name").ToString()) ' you can also use

ls.SubItems.Add(reader.Item("CodeDesc").ToString())

ls.SubItems.Add(reader.Item("Debit").ToString())

TheTotal = TheTotal + Cint(reader.Item("Debit"))

lv.ListView1.Items.Add(ls)

End While

myConnection.Close()

lv.ListView1.Items.Add("")

lv.ListView1.Items.Add("")

ls = lv.ListView1.Items.Add("Total")

ls.SubItems.Add(" ")

ls.SubItems.Add(TheTotal)

but ei, im having this error after i've add the parts of your codes...

"Cannot add or insert the item '' in more than one place. You must first remove it from its current location or clone it.
Parameter name: item "

thanks...



 
 
syndicate





PostPosted: Visual Basic Express Edition, listview display Top

and one more thing..i know my codes read all the data/columns as specified by my query.. but, how can i skip those rows that do not contain data.. say for example:

name codedesc debit

remie 01 1000

armie 01

conie 02 100

cecil 03

then, i want to display data in a separate form like this:

debit

1000

100

how can i code it i will display the debit column from the database in such a way that when i display the data, there will be no empty columns... thanks...........