Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics 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
 
Old May 7th, 2004, 09:55 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default Refreshing Datagrids

I have various grids that are loaded with data on the form load and upon an event the I re-create the datasets, adapters etc and then assign these to my grids showing new data. However, the grids are not refreshing and contain the old data, even though when I look at the values for the dataset etc in the immediate window the new datasets etc hold the correct data.

Help

Thanks in advance

Louisa

 
Old May 8th, 2004, 07:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

DataGrids have a Refresh() method, you can try that...
 
Old May 10th, 2004, 03:02 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have been using the refresh method, but it still contains the old data.

Louisa

 
Old May 10th, 2004, 03:21 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Can you post the relevant parts of the code? It's a bit hard to guess what's going on without actually seeing the code.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 10th, 2004, 04:07 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the code I have been using


  'Declaring CUTTING Variables
        Dim StrCutting As String, CuttingAdapter As New OleDb.OleDbDataAdapter
        Dim CuttingData As New DataSet, CuttingCount As Integer
        Dim StrCuttingMax As String, CuttingMaxData As New DataSet
        Dim CuttingMaxAdapter As New OleDb.OleDbDataAdapter
        '///

 'CUTTING
        'Populating the grid
        StrCutting = "Select JobNo, CuttingEUs, priority, RALcolour from job where omit = false and station = 'cutting' order by priority"
        CuttingAdapter = New OleDb.OleDbDataAdapter(StrCutting, myConnection)
        CuttingAdapter.Fill(CuttingData, "job")

        'If CuttingData.Tables(0).Rows.Count > 0 Then
        Module1.FrmLeft.GridCutting.DataSource = CuttingData
        Module1.FrmLeft.GridCutting.DataMember = "Job"
        'End If

        CuttingAdapter.Dispose()
        CuttingAdapter = Nothing
        CuttingData.Dispose()
        CuttingData = Nothing
        Module1.FrmLeft.GridCutting.Refresh()
        '///////////////////

The CuttingData contains the correct number of records, however the grid does not and contain the previous dataset assigned to it.

Thanks in advance

Louisa

 
Old May 10th, 2004, 04:26 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

This is really weird. I tried your code (albeit with a SqlAdapter) from two buttons. Each button would execute a select statement and assign the DataSet to the DataGrid. By clicking the two buttons, I can switch between the two DataSets without a problem.
When I change the underlying value in the database, the changes are reflected in the DataGrid immediately, as you'd expect.

From what method do you call this code? Do you have other methods setup (e.g. Load stuff, maybe some Event handlers) that override your grid?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 10th, 2004, 04:37 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That is really odd, I call this from an keypress event when a barcode is scanned. I have almost the same code in the form load, which gives the grid its intiall values and the scanned bar code then changes the values in the database, but this is never reflected in the grid.

Thanks for your help.

Louisa
 
Old May 10th, 2004, 04:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Just a wild guess: Could it be that the UPDATE statement and the new SELECT statement are both executed against the same transaction? Maybe the database hasn't been really updated when you execute the SELECT statement.
Try a different connection, or commit any open changes to the database first before you select the data again.

And are you sure the code is hit? When you set a breakpoint, does it reach the code you posted here?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 10th, 2004, 10:04 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have made sure that it is updating the database etc and also that it does update the database before it reaches the databinding.

I have taken out all the code except for this section, so I can see what it is doing more clearly. I think it is where I assign it to the page as I do the same code for two pages, but on the same event. For the page that the code is on I do not specfy which page for example I just put the grid name. However, for the grids that are on the other page I put frmname.gridname, after I have put in frmname as new frmname, is this correct, as I think this is where I am going wrong.

Very confused

Louisa

 
Old May 10th, 2004, 11:38 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have even tried something as simple as

Dim left1 As New FormLeft1

        left1.Hide()

but it still doesn't work, I put a break point on the above so I now it is hitting it, but why isn't it working?

Help

Louisa






Similar Threads
Thread Thread Starter Forum Replies Last Post
datagrids dhoward VB.NET 2002/2003 Basics 8 May 24th, 2007 09:07 AM
Datagrids dhoward VB.NET 2002/2003 Basics 1 January 2nd, 2007 01:06 AM
refreshing XML withour refreshing the page sasidhar79 XML 1 January 12th, 2005 05:16 AM
Datagrids Louisa VB.NET 2002/2003 Basics 2 September 25th, 2004 09:55 AM
Tabbing in Datagrids rotnative ASP.NET 1.0 and 1.1 Basics 3 June 6th, 2003 02:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.