|
-
May 27th, 2008, 12:02 PM
#1
Thread Starter
Addicted Member
[2005] Refresh Datagridview?
Hi all,
I am currently having a problem getting my datagridview to update after I have edited a record.
First off, I edit the record on a seperate form. I then pass those values (id and nbr) back to a function on the main form, and that function in turn calls an SQL query to get the updated record.
Code:
Public Function RefreshTable(ByRef id As String, ByRef nbr As String) As Boolean
Dim coll As New User
Dim i As Integer
Try
'get the most recent record(s)
DataMgr.GetRec(necessary parameters here)
Catch ex As Exception
If MessageBox.Show("No records found for the id/nbr combination entered", "Application Error", MessageBoxButtons.OK) _
= Windows.Forms.DialogResult.OK Then
Me.Focus()
End If
End Try
'clear the datagrid
DataGridView1.Rows.Clear()
'set the size of the grid
DataGridView1.Width = 643
DataGridView1.Height = 160
'fill the datagrid with the collection data
For i = 0 To coll.Count - 1
DataGridView1.Rows.Add(coll(i).id, coll(i).nbr).ToString()
Next
End Function
The issue is that the datagridview does not change. It displays the same record(s) and does not show me the updated version of the record I just changed.
I'm scratching my head because the collection, at this point, contains the most updated record from the database, but I simply cannot get the record to display on the grid. I'm sure it's something easy that I'm missing (as usual), but I have no idea what it is.
If my post helped you, please rate it!
Languages: VB/ASP.NET 2005, C# 2008,VB6
Databases: Oracle (knowledge not currently in use), DB2
FROM Customers
WHERE We_Know_What_We_Want <> DB.Null
SELECT *
0 rows returned
-
May 27th, 2008, 01:53 PM
#2
Thread Starter
Addicted Member
Re: [2005] Refresh Datagridview?
If my post helped you, please rate it!
Languages: VB/ASP.NET 2005, C# 2008,VB6
Databases: Oracle (knowledge not currently in use), DB2
FROM Customers
WHERE We_Know_What_We_Want <> DB.Null
SELECT *
0 rows returned
-
May 27th, 2008, 02:18 PM
#3
Re: [2005] Refresh Datagridview?
I see
DataMgr.GetRec(necessary parameters here)
But I see that you are adding values from "coll" to the datagridview. Is DataMgr.GetRec actually updating coll? It doesn't seem to be "getting" anything.
-
May 27th, 2008, 03:19 PM
#4
Thread Starter
Addicted Member
Re: [2005] Refresh Datagridview?
GetRec just collects the information needed. It is located in a separate class.
I stepped through the code and I am absolutely positive that when I call GetRec, the collection has the most up-to-date records from the table. It's just for some reason the gridview isn't updating.
If my post helped you, please rate it!
Languages: VB/ASP.NET 2005, C# 2008,VB6
Databases: Oracle (knowledge not currently in use), DB2
FROM Customers
WHERE We_Know_What_We_Want <> DB.Null
SELECT *
0 rows returned
-
May 27th, 2008, 03:24 PM
#5
Re: [2005] Refresh Datagridview?
Then clear it as you're doing now, then set its datasource to null. Then loop through as you're doing currently and add the values in.
Also, why are you not setting the datasource of the datagridview, why are you manually looping and adding the data to the cells in?
-
May 27th, 2008, 04:31 PM
#6
Thread Starter
Addicted Member
Re: [2005] Refresh Datagridview?
I am just doing the same thing for this function as I do for the search event.
I tried your suggestion, and I still can't get the updated record to display in the datagridview. It just keeps showing the same record, as if I never cleared it.
Code:
'clear the datagrid
DataGridView1.Rows.Clear()
DataGridView1.DataSource = Nothing
For i = 0 To coll.Count - 1
DataGridView1.Rows.Add(coll(i).id, coll(i).nbr).ToString()
Next
'set the size of the grid
DataGridView1.Width = 643
DataGridView1.Height = 160
End Function
If my post helped you, please rate it!
Languages: VB/ASP.NET 2005, C# 2008,VB6
Databases: Oracle (knowledge not currently in use), DB2
FROM Customers
WHERE We_Know_What_We_Want <> DB.Null
SELECT *
0 rows returned
-
May 28th, 2008, 11:21 AM
#7
Thread Starter
Addicted Member
Re: [2005] Refresh Datagridview?
One thing I thought about....
The refresh function is located on the search form. However, I am calling the function from the "Edit Record" form. Does this make a difference? In other words, do I need to hand control back to the search form before calling this function?
For instance, this is what I'm using in my edit form:
Code:
'call function from search form
Search.RefreshTable(necessary parameters)
'close edit form
Me.Close()
'change focus back to search form
Search.Focus()
'return control back to search form
Return
End If
End Sub
If my post helped you, please rate it!
Languages: VB/ASP.NET 2005, C# 2008,VB6
Databases: Oracle (knowledge not currently in use), DB2
FROM Customers
WHERE We_Know_What_We_Want <> DB.Null
SELECT *
0 rows returned
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|