can u help me regarding listview control in vb 6...
i want to use listview as datagrid..
i have 3 textboxes, and a list view with 3 coloums.
now when i enter data textboxs, it asks "do u want to add another data?"
when user enters so data, how much he want, and then he presses update button, the the whole data which is in listview, should b updates in database...
please, need help.

Recommended Answers

All 14 Replies

post more info..
what kind of database? MSSQL Server, MySQL, Access??
3 columns? what are the name of your columns?
and where is your effort?? post your code that you've been work..

So you mean to say what ever you enter in text boxes needs to be added into list view, right ?

and i think after 80 posts, you should understand that you need to show some effort to get any help here.

commented: ghatiya +0
commented: agreed +13
commented: Noobs like JA deserve to get no help. Idiots who don't follow guidelines deserve to be told. +9
Private Sub Form_Load()
ListView1.FullRowSelect = True
Call MyDatacon
Dim lvx As ListItem
rs.Open "SELECT * from tREE", con, adOpenStatic, adLockOptimistic
Do While Not rs.EOF
Set lvx = ListView1.ListItems.Add(, , rs.Fields("ID"))
lvx.SubItems(1) = rs.Fields("NAME")
lvx.SubItems(2) = rs.Fields("PID")
rs.MoveNext
Loop
End Sub

this is what showing the records in listview, that are already stored.

Private Sub Text5_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then
Call MyDatacon
Set rs = New ADODB.Recordset
rs.Open "SELECT * from tREE", con, adOpenKeyset, adLockOptimistic
rs.AddNew
rs.Fields("ID") = Text3(0).Text
rs.Fields("NAME") = Text4(0).Text 
rs.Fields("PID") = Text5(0).Text  
rs.Update
Dim a As Integer
a = MsgBox("Do you want to add another entry", vbYesNoCancel, "Confirm")
If a = vbYes Then
Text3(0).Text = ""
Text4(0).Text = ""
Text5(0).Text = ""
Text3(0).SetFocus
ElseIf a = vbNo Then
Text3(0).Enabled = False
Text4(0).Enabled = False
Text5(0).Enabled = False
End If
rs.MoveLast
ListView1.ListItems.Clear
Call Form_Load
End If
End Sub

this is working as, when i am entering anydata from textboxes, it first stores in database and then it shows in listview..
i want,when i enter data it should b temperory stored in listview, when i press update key, then it should b store in database,,,?

@ Jx, its MSSQL 2000, first coloum is id, 2nd is name, third is pid...
i have posted where i have reached,....

and debis ur replies never helped me, so plzzz avoid replying my threads...
thank u very much...

commented: misbehaving idiot. -2

I have gone so far...
have a look at this code,i am explaining it...

Private Sub Form_Load()
Call Mydatacon
rs.Open "SELECt * from AAAAA_DEMO", con, adOpenKeyset, adLockOptimistic
Combo1.Enabled = False
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
While Not rs.EOF
Set lvx = ListView1.ListItems.Add(, , rs!code)
lvx.SubItems(1) = rs!descprtion
lvx.SubItems(2) = rs!cooler
lvx.SubItems(3) = rs!quan
rs.MoveNext
Wend
rs.Close
con.Close
End Sub

Private Sub CmdAdd1_Click() ' this adds the records from textboxes in listview.
If Text1.Text = "" And Text2.Text = "" And Text3.Text = "" Then
MsgBox "Please enter first fields"
Else
Dim a As Integer
Set lvx = ListView1.ListItems.Add(, , Combo1.Text)
lvx.SubItems(1) = Text1.Text
lvx.SubItems(2) = Text2.Text
lvx.SubItems(3) = Text3.Text
a = MsgBox("do u want to add another entry!!", vbYesNo)
If a = vbYes Then
Combo1.SetFocus
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Else
Combo1.Enabled = False
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Combo1.Text = "0"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End If
End If
End Sub


Private Sub CmdRemove1_Click()'if a user wants to remove added item from listview, here he can remove selected item.
ListView1.ListItems.Remove (ListView1.SelectedItem.Index)
End Sub

Private Sub CmdSave1_Click()' then all the rest records should b save in database from listview. in this code only last record of listview is added, not all in list
Call Mydatacon
Set rs = New ADODB.Recordset
rs.Open "SELECT * from AAAAA_DEMO", con, adOpenStatic, adLockOptimistic

rs.AddNew
While Not ListView1.ListItems(1).Text = ""
rs!code = lvx
rs!descprtion = lvx.SubItems(1)
rs!cooler = lvx.SubItems(2)
rs!quan = lvx.SubItems(3)
rs.Update
Wend
rs.Close
con.Close
End Sub

change this part.

Private Sub CmdSave1_Click()
Call Mydatacon
Set rs = New ADODB.Recordset
For i = 1 To ListView1.ListItems.Count
    Set rs = Nothing
    rs.Open "SELECT * from AAAAA_DEMO", Con, adOpenStatic, adLockOptimistic
    rs.AddNew
    rs!code = ListView1.ListItems(i).Text
    rs!descprtion = ListView1.ListItems(i).SubItems(1)
    rs!cooler = ListView1.ListItems(i).SubItems(2)
    rs!quan = ListView1.ListItems(i).SubItems(3)
    rs.Update
Next i
rs.Close
con.Close
End Sub

@ JX, there is still problem apearing, it is also saving all those records, which are already saved in list.?
means on first execution i added 4 records, and saved that, and now when i m adding new more records, that are also displaying and also added in database again..
can't it happen, it updates only those records which are newly added?

Just refresh the listview to show the newest records...

Listview1.Refresh

This AFTER adding the new record.:)

no andre....that is not a problem,
ihave customer that is already assigned some data, now once again i want to assign him new data, when im assigning new data, the old one, which is alredy stored in database, and currently showing in listview is being again stored in database.

how about two listview.
one for input data (added data to listview then add it), one for displaying data.

no i have used only one, i have changed the concept..now when user will add new records, the listview will b clear, and new records will b added to list and when user will update that records, list will b refreshed and it will show old and new both records now, if anyone wants to change anything, then i have kept the button of delete, he can delete any previous or new record...

i think its a better option...what do u say?

no i have used only one, i have changed the concept..now when user will add new records, the listview will b clear, and new records will b added to list and when user will update that records, list will b refreshed and it will show old and new both records now, if anyone wants to change anything, then i have kept the button of delete, he can delete any previous or new record...

i think its a better option...what do u say?

Yes.. Its a better option.. Nice idea :)

and debis ur replies never helped me, so plzzz avoid replying my threads...
thank u very much...

1. Please start using proper words, "ur, plzz, u" are not you should know better then after the number of posts you made
2. If the replies are not helpful to you then ignore them, no need for this sort of replies that can be view as offending

@OTHERS
If a member reply is offensive please report it, however if your suggestions/help is not appreciated then what is point of reporting that person as expecting "spoon feeding"?

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.