Datagridview problem

E

Eric

Hi,

With the following code I show some information to the user:

Dim ofd As New OpenFileDialog
ofd.CheckFileExists = True
ofd.CheckPathExists = True
ofd.DefaultExt = "HCF"
ofd.Filter = "Claim form files (*.HCF)|*.hcf|All files (*.*)|*.*"
ofd.InitialDirectory = "c:\"
ofd.Multiselect = False
ofd.RestoreDirectory = True
ofd.ShowHelp = False
ofd.ShowReadOnly = False
ofd.SupportMultiDottedExtensions = True
ofd.Title = "Open data file"
dgr = ofd.ShowDialog

If dgr = Windows.Forms.DialogResult.Cancel Then Exit Sub
Try
dsData.Tables.Remove("overtime")
Catch ex As Exception
End Try

dsData.ReadXml(ofd.FileName)

Me.dgvData.DataSource = dsData
Me.dgvData.DataMember = "overtime"
Me.dgvData.ClearSelection()
Me.dgvData.Refresh()

The first time I click on the OPEN button, this goes fine, but any next time
it loads the data in the dataset, but nothing is shown in the DataGridView.

How is this possible, am I doing something wrong?

rg,
Eric

P.s. it's in VB2005.
 
F

Fritz Francis

Hello Eric,

I think I need more information about the code. For instance, do you
intstantiate the DataSet in the click event handler of your button? Also why
do you remove the table from the DataSet? Why not just clear the rows using
the Clear() method of the DataTable?

Regards,

Fritz
 

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