Question Datagridview not displaying values from datatable

timh

Well-known member
Joined
Nov 28, 2008
Messages
50
Programming Experience
Beginner
Hello.

I have searched long and hard for an answer to this problem, to no avail!

First off, let me say that I am a "hobbyist" and enjoy tinkering with Visual Basic. All my "knowledge" is scoured from books and the internet, so my coding is probably horrendous...

I am using Visual Basic 2010 Express and have a very simple requirement.

I have an XML file containing a parent element "eventdata", which then contains two complex elements "eventdetails" and "entrant".

"eventdetails" is made up of two elements, "eventname" and "eventdate".

"entrant" is made up of several elements, such as "surname", "firstname", "dateofbirth" etc.

What I am trying to do is read the "eventdetails" element from the XML and display it in a datagridview. I am doing this as a dummy run, prior to working with the "entrant" element, as at the moment the only the "eventdetails" element is populated in the XML file. Ultimately, it is a list of "entrants" that I want to display in this datagridview.

I have added a dataset called "eventdata" to the form with the datagridview and also "eventdatabindingsource", where the datasource is "eventdata" and the datamember is "eventdetails".

When I run the form, with the XML file loaded, the column headers appear, but no data??

Can someone tell me what I am doing wrong please?

Thanks very much.

Tim
 
We can't really tell you what you're doing wrong because we don't really know what you're doing. You should show us the code that loads the XML and populates the grid.
 
Ok, here's the code. There doesn't seem to be much to it, which is probably the issue. I copied it from another example, which seemed to work fine...

VB.NET:
        Eventdata.ReadXml(My.Settings.lastfile)

        DataGridView1.DataSource = Eventdata
        DataGridView1.DataMember = "eventdetails"

This is the XML source...

VB.NET:
<?xml version="1.0" encoding="utf-8"?>
<eventdata>
  <eventdetails>
    <eventname>Pub Run</eventname>
    <eventdate>04/04/2012</eventdate>
  </eventdetails>
  <entrant>
  .
  .
  </entrant>
</eventdata>

Thanks,

Tim
 
Thanks for the tip. Sorted it now.

I had confused myself by adding a dataset and databindingsource to the form with the datagridview and using the property fields to try and set them up.

In the end, it was a simple matter of deleting those controls and then using the following code...

VB.NET:
Dim myeventdata as New Dataset
myeventdata.readXML(my.settings.lastfile)

DataGridView1.Datasource=myeventdata
DataGridView1.Datamember="eventdetails"

Job done!

Thanks again.

Tim
 
Back
Top