Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 86,399 VB Programmers. There are 1,457 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a VB Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

displaying a newly added record in a listview

 
Reply to this topicStart new topic

displaying a newly added record in a listview

emkaye
post 25 Feb, 2008 - 08:56 AM
Post #1


New D.I.C Head

*
Joined: 12 Aug, 2007
Posts: 28



i need another help regarding listview.

I have a listview and command buttons like cmdAdd, cmdSave, cmdEdit, and cmdDelete. When I click cmdAdd, it will validate flight number. And if it is accepted, cmdSave will be enabled. When cmdSave is clicked, the system will add a new flight. I wanted to have the newly added record to be seen in the lisview right after I clicked cmdSave. I have tried to use lvTariff.Refresh but nothing happens. The newly added record only appears when I stop then run the program again. Below is my code:

CODE

Private Sub cmdSave_Click()
Dim AddNewFlight As String
If txtFlightNo.Enabled = False Then
    
    'check blank fields
    If VerEntry Then
    MsgBox "Please fill up the fields you left blank.", vbInformation, "Incomplete information detected..."
    
    Else
    'access to database(save to tblEmpinfo)
    AddNewFlight = "insert into TariffAP ([FL_NO],[ROUTE],[Y],[S],[Q],[V], [B], [X],[K],[E],[T],[U], [M], [L],[PH],[YQ]) values  ('" & txtFlightNo & "' , '" & txtRoute & "' , '" & txtBCC(0) & "' , '" & txtBCC(1) & "' , '" & txtBCC(2) & "' , '" & txtBCC(3) & "' , '" & txtBCC(4) & "', '" & txtBCC(5) & "', '" & txtBCC(6) & "' , '" & txtBCC(7) & "' , '" & txtBCC(8) & "' , '" & txtBCC(9) & "' , '" & txtBCC(10) & "', '" & txtBCC(11) & "', '" & txtPH & "', '" & txtYQ & "' ) "
    Set NewFlightRec = myConn.Execute(AddNewFlight)
              
    'access to database(save to tblCompany)
    'CompInfoNew = "insert into [tblCompany] ([EMPID],[POSITION]) values ('" & txtEmpID & "', '" & cboPosition & "')"
    'Set CompInfo = myConn.Execute(CompInfoNew)
    
    'determine success of adding
    MsgBox "The new record has been added succesfully.", vbInformation, "Adding new record..."
    enableCMDsSave
    lvTariff.Refresh
    
    End If
    
End If
End Sub


It was also the same thing I wanted to happen when I delete and edit records. When I click cmdDelete and the record was successfully deleted, I wanted that that record will be deleted from the listview. Same as with editing records, I wanted to see that the edited record has changed in the listview right after I click cmdUpdate. Below are my codes for cmdDelete and cmdEdit:

CODE

Private Sub cmdDelete_Click()

'#1. declaration of variables
Dim DelRec As String


'#2. delete employee
DelRec = MsgBox("Are you sure you want to delete record?", vbQuestion + vbYesNo, "Deleting record...")

If DelRec = vbYes Then
Set DelFlightRec = myConn.Execute("Delete * from TariffAP where FL_NO=" & Str(Val(txtFlightNo.Text)))
MsgBox "Record has been deleted!", vbInformation, "Deleted record..."
    
    'clear fields
    ClearTextBox
    txtFlightNo = ""
    lvTariff.Refresh

Else
Me.Refresh

End If

End Sub

Private Sub cmdEdit_Click()
Dim UpdateFlight As String

    

If cmdEdit.Caption = "&EDIT" Then
    DisableCMDsEdit
    EnableTextBoxADD
    txtFlightNo.Enabled = True
    lvTariff.Enabled = False
    
    Else
    If VerEntry Then
    MsgBox "Please fill up the blank fields left.", vbInformation, "Verifying..."
    
    Else

    UpdateFlight = "update TariffAP set ROUTE='" & txtRoute & "', Y='" & txtBCC(0) & "',S ='" & txtBCC(1) & "', Q='" & txtBCC(2) & "', V ='" & txtBCC(3) & "' where FL_NO=" & Str(Val(txtFlightNo))
    Set UpdateFlightRec = myConn.Execute(UpdateFlight)

    MsgBox "Record successfully updated.", vbInformation, "Updating..."
    cmdEdit.Caption = "EDIT"
    enableCMDsSave
    cmdSave.Enabled = True
    lvTariff.Enabled = True
    DisableTextBoxAdd
    End If
    
End If
End Sub



thanks in advance!

cool.gif
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


k_bryan
post 28 Apr, 2008 - 01:40 PM
Post #2


New D.I.C Head

*
Joined: 28 Apr, 2008
Posts: 1

EmKaye,

Per MSDN, Listview.refresh just causes the listview control to repaint using the data it already has loaded. To show changes you've made by insert or delete, you will need to either manually add or subtract the record.. or reload the control with the updated dataset from your database.

Yes, I saw that .refresh and thought, "How convenient." Unfortunately for both of us, it didn't work that way.

Have a great day!
Kerry
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

emkaye
post 8 May, 2008 - 12:39 AM
Post #3


New D.I.C Head

*
Joined: 12 Aug, 2007
Posts: 28

reload the control with the updated dataset from your database?

can you please explain it to me more. i would like to know more about it.

thanks for the reply.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 06:12AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month