datagrid will not display dataset the second time around

rustyLI

New member
Joined
Mar 28, 2005
Messages
2
Programming Experience
5-10
the first time I load the datagrid with a dataset it works fine.
I then do a new query reload the dataset with new data which fills fine.

But the datagrid ends up displaying nothing.
Just the column headings appear with a blank row.

What am I missing
Thanks
Below is the code:

PrivateSub getListGrid()

Dim ff As clsFTP

Dim myFiles() AsString

Dim myflg AsBoolean = False

Dim myret AsBoolean

'used for all the form Dim ds As New DataSet

Dim dtable AsNew DataTable("Files")

Dim row As DataRow

' ff = New clsFTP(myRemoteHost, _

' myRemotePath, _

' myRemoteUser, _

' myRemotePassword, _

' myRemotePort)

ff = New clsFTP(myRemoteHost, _

".", _

myRemoteUser, _

myRemotePassword, _

myRemotePort)

'Try to log on to the FTP server.

ds.Clear()

Try

ds.Tables.Remove("Files")

Catch ex As Exception

EndTry

With dtable.Columns

.Add("Count",
GetType(System.Int32))

.Add("FileName",
GetType(System.String))

.Add("DownLoad",
GetType(System.Boolean))

EndWith

ds.Tables.Add(dtable)

If (ff.Login() = True) Then

myret = ff.ChangeDirectory(myRemotePath)

If myret = FalseThen MsgBox("Could not reach FTP Site - restart application")

ff.SetBinaryMode(
False)

myFiles = ff.GetFileList(" ")

Dim myFile AsString

If myFiles.Length > 0 Then

Dim cnt AsInteger

cnt = 0

ForEach myFile In myFiles

cnt += 1

row = ds.Tables("Files").NewRow

row(0) = cnt

row(1) =
CStr(myFile)

row(2) =
False

ds.Tables("Files").Rows.Add(row)

ds.Tables("Files").AcceptChanges()

' MsgBox(myFile)

Next

Try

ff.CloseConnection()

Catch

Finally

ff = Nothing

EndTry



EndIf

EndIf



dg.TableStyles.Clear()

dg.DataSource =
Nothing



dg.SetDataBinding(ds, "Files")



Dim styles AsNew DataGridTableStyle

styles.MappingName = "File"

Dim colCount AsNew DataGridTextBoxColumn

colCount.MappingName = "COUNT"

colCount.HeaderText = "Count"

colCount.Width = 40

styles.GridColumnStyles.Add(colCount)

Dim colF AsNew DataGridTextBoxColumn

colF.MappingName = "FILENAMES"

colF.HeaderText = "FileName"

colF.Width = 200

styles.GridColumnStyles.Add(colF)

Dim colDownLoad AsNew DataGridBoolColumn

colDownLoad.MappingName = "DownLoad"

colDownLoad.Width = 70

colDownLoad.HeaderText = "DownLoad"

styles.GridColumnStyles.Add(colDownLoad)

dg.TableStyles.Add(styles)

dg.Visible =
True

ff = Nothing

EndSub

 
answered my own question sort of

I found a fix to my problem, by separating several steps:
1) When the form loaded I use the styles to format the grids columns.
2) Also while the form loaded I formated the dataset with a table and the definition of the columns in the table, and bound the dataset to the datagrid
3) Finally when ever I do a new query I just dataset.clear and refill it, the datagrid reflects the changes in the dataset correctly.

However, I still believe I should be able to somehow clear the datagrid - give it new columns and rebind it to another dataset. Which clearly wouldn't work as my example didn't work. I am missing some type of clear and recreate statements that I can't figure out.
 
Back
Top