gridview clear & refresh

J

jcoon

All,

I need help understanding how you clear then reload or refresh the grid
view. I'm loading the grid view from a xml that can be edited or added to
then saved back. I think I need to clear then reload the grid to reflect
edits saved back to the xml file. currently if I make and edit to the xml
and post back the data it is not reloaded in the gridview without starting
the routine again. how can reload this data to the gridview.



thank you

john



Private Sub btnReadXML_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnReadXML.Click

DataGridView1.Columns.Clear()

Dim filePath As String

filePath = "C:\xml-write\Airports-Runways-test.xml"

dsAirports.ReadXml(filePath)

With DataGridView1

..DataSource = dsAirports

..DataMember = "Airport"

End With

'DataGridView1.Refresh() 'how to reload xml file after clear

End Sub
 
M

MBUnit

jcoon said:
All,

I need help understanding how you clear then reload or refresh the grid
view. I'm loading the grid view from a xml that can be edited or added
to then saved back. I think I need to clear then reload the grid to
reflect edits saved back to the xml file. currently if I make and edit
to the xml and post back the data it is not reloaded in the gridview
without starting the routine again. how can reload this data to the
gridview.



thank you

john



Private Sub btnReadXML_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnReadXML.Click

DataGridView1.Columns.Clear()

Dim filePath As String

filePath = "C:\xml-write\Airports-Runways-test.xml"

dsAirports.ReadXml(filePath)

With DataGridView1

.DataSource = dsAirports

.DataMember = "Airport"

End With

'DataGridView1.Refresh() 'how to reload xml file after clear

End Sub

You have to make a function that reads the XML, creates the dataset and
returns the dataset from the function to the control.

I don't use VB that much anymore I use C# mostly.

But it's something like this.

public fucntion GetAirports() as Dataset

Dim filePath As String

filePath = "C:\xml-write\Airports-Runways-test.xml"

dsAirports.ReadXml(filePath)

return dsAirports

end fucntion


Then it's this.

DataGridView1.Columns.Clear()

With DataGridView1

.DataSource = GetAirports()

.DataMember = "Airport"

End With

'DataGridView1.Refresh() 'if you like but you don't need it because
you did the clear and reloaded the data.

End Sub

You got it?
 
M

MBUnit

jcoon said:
All,

I need help understanding how you clear then reload or refresh the grid
view. I'm loading the grid view from a xml that can be edited or added
to then saved back. I think I need to clear then reload the grid to
reflect edits saved back to the xml file. currently if I make and edit
to the xml and post back the data it is not reloaded in the gridview
without starting the routine again. how can reload this data to the
gridview.



thank you

john



Private Sub btnReadXML_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnReadXML.Click

DataGridView1.Columns.Clear()

Dim filePath As String

filePath = "C:\xml-write\Airports-Runways-test.xml"

dsAirports.ReadXml(filePath)

With DataGridView1

.DataSource = dsAirports

.DataMember = "Airport"

End With

'DataGridView1.Refresh() 'how to reload xml file after clear

End Sub

Oh, one other thing, you can execute the GetAirports() and bind it to
the Datasource right after the Refresh if you like too.
 
J

jcoon

MBUnit,

Thank you,

I'm new to Vb. If I already read the xml file into the datagridview do I
still need to generate the fuction that builds the dataset then populates
the datagridview?
The dataset hold the data for thr control, is that coorect?

have a great day,
john
 

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