Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 27th, 2004, 05:14 PM
Authorized User
 
Join Date: Jun 2003
Location: Mexico City, Distrito Federal, Mexico.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Refresh Listview after Database Update

Hi All,

I have run into a problem. I select a user from a listview by double clicking and it displays a small form. Within this form you can change the details in text boxes. When the user clicks OK I want to update the database and then close the window and update the listview on the original page.

I have written the code and it works except one little detail. The listview does not refresh. The refresh command works but it doesn't display the new updated data. However after several seconds, my manual refresh shows the new data. What I want to do is make it instantaneous, so as soon as the OK is clicked the new information is displayed.

Code:
Private Sub Command2_Click()

  Call UpdateDBGroup
  frmDirectory.ListView1.ListItems.Clear
  Unload Me

End Sub

Private Sub UpdateDBGroup()

  Dim UpdateGroup As Database
  Dim strSQL As String

  strSQL = "SELECT * FROM Groups WHERE Name = '" & rsGroupSelected & "';"
  Set UpdateGroup = OpenDatabase(App.Path & "\dispatcher.bdp", False, False, ";Pwd=1354513")

  strSQL = "UPDATE Groups SET" _
         & " [FullName] = '" & Trim(Text1.Text) & "'," _
         & " [Channel] = " & Trim(Text2.Text) & "," _
         & " [Description] = '" & Trim(Text3.Text) & "'" _
         & " WHERE Name = '" & rsGroupSelected & "';"
  UpdateGroup.Execute (strSQL)

'  Dim strUpdCn As ADODB.Connection
'  Set strUpdCn = New ADODB.Connection
'  strUpdCn.Open strCn
'
'  Dim strSQL As String
'  strSQL = "UPDATE Groups SET" _
'         & " [FullName] = '" & Trim(Text1.Text) & "'," _
'         & " [Channel] = " & Trim(Text2.Text) & "," _
'         & " [Description] = '" & Trim(Text3.Text) & "'" _
'         & " WHERE Name = '" & rsGroupSelected & "';"
'  strUpdCn.Execute (strSQL)

End Sub
as you can see I have been playing with two different methods both with the same result.
The user details form is opened modally and upon closing it runs a function to refresh the listview.

I have toyed with ideas of DBEngine.Idle to delay the listview refresh until the database engine has finished the operation but I still want the change instantly.

Any suggestions you might have will be greatfully received

Many thanks,

Paul
Reply With Quote
  #2 (permalink)  
Old September 28th, 2004, 02:10 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I Paul have had similar problems where new records that have been added do not show up straight away.

The only way that I ever found to beat this was that when you have added the new item, before refreshing the list, close the current database connection and re open another one. This will then include the new record.

Bizzare but it seems to work.

Cheers

Byron

Reply With Quote
  #3 (permalink)  
Old September 28th, 2004, 08:05 AM
Authorized User
 
Join Date: Jun 2003
Location: Mexico City, Distrito Federal, Mexico.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Byron,

Thanks for that tip. However, I can't seem to get it to work. Is it possible that you could send me a bit of example code on how you achieved the correct result.

Many thanks,

Paul
Reply With Quote
  #4 (permalink)  
Old September 28th, 2004, 08:16 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

how are you populating your list view.

Is it linked to an underlying ado data control?

Cheers

Byron

Reply With Quote
  #5 (permalink)  
Old September 28th, 2004, 08:20 AM
Authorized User
 
Join Date: Jun 2003
Location: Mexico City, Distrito Federal, Mexico.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Byron,

A function is called as soon as the form is closed, and that function is as follows.

Code:
Private Sub LoadGroups()

  Dim strSQL2 As String
  Dim rsPopulate As New ADODB.Recordset
  Dim li As ListItem

  strSQL2 = "SELECT * FROM Groups ORDER BY Name"
  rsPopulate.Open strSQL2, strCn, adOpenStatic, adLockBatchOptimistic

  Do Until rsPopulate.EOF
    Set li = ListView1.ListItems.Add(, , rsPopulate!Name & "", 1, 5)
    li.SubItems(1) = rsPopulate!FullName
    li.SubItems(2) = rsPopulate!Description
    rsPopulate.MoveNext
  Loop
  rsPopulate.Close
  Set rsPopulate = Nothing
 
End Sub
Any ideas...?

Cheers,

Paul
Reply With Quote
  #6 (permalink)  
Old September 28th, 2004, 08:29 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If strCn is your current open connection. Is that the connection that was used to update the record details.

if is is when you close the form try closing strCn and re-opening it before opening the recordset. The newly opened connection shuld then pick up the changes.

OR define a new connection as below
Private Sub LoadGroups()

  Dim strSQL2 As String
  Dim rsPopulate As New ADODB.Recordset
  Dim li As ListItem
Dim cnn as new ADODB.Connection

cnn.open (connection string)

  strSQL2 = "SELECT * FROM Groups ORDER BY Name"
  rsPopulate.Open strSQL2, cnn, adOpenStatic, adLockBatchOptimistic

  Do Until rsPopulate.EOF
    Set li = ListView1.ListItems.Add(, , rsPopulate!Name & "", 1, 5)
    li.SubItems(1) = rsPopulate!FullName
    li.SubItems(2) = rsPopulate!Description
    rsPopulate.MoveNext
  Loop
  rsPopulate.Close
  Set rsPopulate = Nothing
cnn.close
set cnn=nothing

End Sub



Cheers

Byron

Reply With Quote
  #7 (permalink)  
Old September 28th, 2004, 08:48 AM
Authorized User
 
Join Date: Jun 2003
Location: Mexico City, Distrito Federal, Mexico.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's sorted it.

Many many thanks Byron...

I really appreciate your help.

Paul
Reply With Quote
  #8 (permalink)  
Old September 28th, 2004, 08:50 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

glad to be of help.

Cheers

Byron

Reply With Quote
  #9 (permalink)  
Old March 14th, 2011, 04:33 AM
Registered User
 
Join Date: Mar 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reloading data into your listview control

This might be the solution you are looking for in regards to getting your listview control to reload the data after you have delete/add. Took me awhile to find it. Basically you have to fill the table adapter again with the data from your dataset.

Code:
TableAdapterName.Fill(DataSetName.TableName)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Save Listview Data to a DataBase ecabralrojas Beginning VB 6 0 June 30th, 2008 10:33 AM
how to update table with listview items Singh591 Pro VB.NET 2002/2003 0 December 30th, 2006 10:13 PM
Binding a comboBox to update a listView Amethyst1984 VB How-To 2 February 28th, 2006 02:07 PM
Remove entries from listview and database on click neo_jakey VB Databases Basics 2 September 20th, 2004 10:37 AM
Using VBScript to update content w/o page refresh ALoPresto Classic ASP Basics 2 July 11th, 2003 12:53 PM



All times are GMT -4. The time now is 12:35 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.