HELP PLEASE: Cannot refresh Datagrid

J

Juan Romero

Hey guys, please HELP

I am going nuts with the datagrid control.

I cannot get the damn control to refresh. I am using soap to get information
from a web service. I have an XML writer output the file to a folder, and
then I read it back into the dataset using the dataset1.readxml. Up to this
point, everything works wonderfully. The query executes, the dataset gets
populated, and I get the results displayed in the datagrid.

The problem:

When I run another query, everything goes as before expect that the datagrid
columns WON'T REFRESH. I can see the data changes, but the columns remain,
and since the columns don't match any other column in the new set,
everything is (null).

How do I REFRESH the grid columns?.... I mean, I have tried everything, I
have called the dataset.clear() method, I have called the
dataset.table.clear() method, I have unbound the grid from the datasource
and rebound again, deleted all tables, etc etc etc. I just can't get rid of
the damn columns.

Please help, it's been a long weekend and it is getting frustrating.....

Thank you in advance.

Regards.
 
C

Cor

Juan,
Did you know that there is a special newsgroup
microstof.public.dotned.aspnet.datagridcontrol
I think that you get in that newsgroup the best answer.
Success
Cor
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Juan,

First of all, how do you bind the DataSet? I'd strongly suggest using
SetDataBindingMethod.
Second, do you create TableStyles/ColumnStyles manually? If yes, you might
need to re-create them after a new data source has been bound to the grid.

Probably you could also post a code snippet to illustrate the problem?
 
J

Juan Romero

I am not talking about ASP .NET.

I am talking about the datagrid control for VB .NET

Thanks for your answer anyways.
 
C

Cor

I know Juan,
That group seems to be for special for the ASP.Net datagrid control

I did not say, go away :)

But it is just an advise.
Cor
 
O

One Handed Man [ OHM ]

-- i tried this and it works 4 me. I'm not sue if this is what you were
trying to acheive ?

Public Class Form1

Inherits System.Windows.Forms.Form

Dim ds As New DataSet("MySet")

Dim myTab As DataTable



#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents dg As System.Windows.Forms.DataGrid

Friend WithEvents ClearTab As System.Windows.Forms.Button

Friend WithEvents SaveXML As System.Windows.Forms.Button

Friend WithEvents ReadXML As System.Windows.Forms.Button

Friend WithEvents AddName As System.Windows.Forms.Button

Friend WithEvents aName As System.Windows.Forms.TextBox

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.dg = New System.Windows.Forms.DataGrid

Me.ClearTab = New System.Windows.Forms.Button

Me.SaveXML = New System.Windows.Forms.Button

Me.ReadXML = New System.Windows.Forms.Button

Me.AddName = New System.Windows.Forms.Button

Me.aName = New System.Windows.Forms.TextBox

CType(Me.dg, System.ComponentModel.ISupportInitialize).BeginInit()

Me.SuspendLayout()

'

'dg

'

Me.dg.DataMember = ""

Me.dg.HeaderForeColor = System.Drawing.SystemColors.ControlText

Me.dg.Location = New System.Drawing.Point(144, 128)

Me.dg.Name = "dg"

Me.dg.Size = New System.Drawing.Size(208, 128)

Me.dg.TabIndex = 0

'

'ClearTab

'

Me.ClearTab.Location = New System.Drawing.Point(24, 48)

Me.ClearTab.Name = "ClearTab"

Me.ClearTab.TabIndex = 1

Me.ClearTab.Text = "Clear"

'

'SaveXML

'

Me.SaveXML.Location = New System.Drawing.Point(184, 48)

Me.SaveXML.Name = "SaveXML"

Me.SaveXML.TabIndex = 2

Me.SaveXML.Text = "SaveXML"

'

'ReadXML

'

Me.ReadXML.Location = New System.Drawing.Point(344, 48)

Me.ReadXML.Name = "ReadXML"

Me.ReadXML.TabIndex = 3

Me.ReadXML.Text = "Read XML"

'

'AddName

'

Me.AddName.Location = New System.Drawing.Point(24, 96)

Me.AddName.Name = "AddName"

Me.AddName.TabIndex = 4

Me.AddName.Text = "Add Name"

'

'aName

'

Me.aName.Location = New System.Drawing.Point(112, 96)

Me.aName.Name = "aName"

Me.aName.TabIndex = 5

Me.aName.Text = ""

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(480, 273)

Me.Controls.Add(Me.aName)

Me.Controls.Add(Me.AddName)

Me.Controls.Add(Me.ReadXML)

Me.Controls.Add(Me.SaveXML)

Me.Controls.Add(Me.ClearTab)

Me.Controls.Add(Me.dg)

Me.Name = "Form1"

Me.Text = "Form1"

CType(Me.dg, System.ComponentModel.ISupportInitialize).EndInit()

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim dr As DataRow

ds.Tables.Add("myTable")

myTab = ds.Tables("myTable")

myTab.Columns.Add("FirstName")

dr = myTab.NewRow

dr("FirstName") = "John"

myTab.Rows.Add(dr)

dg.DataSource = ds.Tables("myTable")





End Sub

Private Sub SaveXML_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SaveXML.Click

ds.WriteXml("C:\myxml.txt")

End Sub

Private Sub ReadXML_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ReadXML.Click

ds.Clear()

ds.ReadXml("c:\myxml.txt")

End Sub

Private Sub AddName_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AddName.Click

Dim dr As DataRow

dr = myTab.NewRow

dr("FirstName") = aName.Text

myTab.Rows.Add(dr)

End Sub

Private Sub ClearTab_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ClearTab.Click

ds.Clear()

End Sub

End Class
 
J

Juan Romero

Guys, I just cannot get this %^^$&% datagrid to refresh. I managed to
overcome the columns problem, and here is where I am now:

As you will see in the below piece of code, Once I get the datatable, I EVEN
check to see if it exists on the dataset. If it finds it, IT DELETES all the
rows from the table (another attempt to make it work) and then it drops the
table. After dropping it adds the table again to the dataset.

The intersting part:
Deleting all the records from the table actually makes the grid refresh, so
it looks empty, but when I reload the table, IT DOES NOT DISPLAY THE
RECORDS, it now stays EMPTY.

Sigh.... I have included every possible instruction I KNOW OF to make the
damn grid refresh, yet, it shows nothing...

Please help.

Here is a piece of code:

Dim x As DataTable = GetDataTable(Results)

x.TableName = tvDesc.SelectedNode.Text

If Not DataSetSF.Tables(x.TableName) Is Nothing Then

DataSetSF.Tables(x.TableName).Clear()

DataSetSF.Tables.Remove(x.TableName)

DataSetSF.AcceptChanges()

End If

DataSetSF.Tables.Add(x)

DataSetSF.Tables(x.TableName).AcceptChanges()

DataSetSF.AcceptChanges()

dgresults.SetDataBinding(DataSetSF, tvDesc.SelectedNode.Text)

dgresults.DataMember = tvDesc.SelectedNode.Text

dgresults.CaptionText = x.TableName & " - " &
DataSetSF.Tables(x.TableName).Rows.Count.ToString & " Records."

dgresults.Refresh()

dgresults.Update()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top