 |
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

September 27th, 2004, 05:14 PM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

September 28th, 2004, 02:10 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

September 28th, 2004, 08:05 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

September 28th, 2004, 08:16 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how are you populating your list view.
Is it linked to an underlying ado data control?
Cheers
Byron
|

September 28th, 2004, 08:20 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

September 28th, 2004, 08:29 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

September 28th, 2004, 08:48 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That's sorted it.
Many many thanks Byron...
I really appreciate your help.
Paul
|

September 28th, 2004, 08:50 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
glad to be of help.
Cheers
Byron
|

March 14th, 2011, 04:33 AM
|
Registered User
|
|
Join Date: Mar 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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)
|
|
 |