|
-
Feb 18th, 2007, 02:50 PM
#1
Thread Starter
New Member
[2.0] dataGridView + XML
Good Evening,
Straight to the point:
I have a dataGridView that is populated with an xml file, as follows:
Code:
private void Form1_Load(object sender, EventArgs e)
{
string filePath = "SessionsList.xml";
dataSet1.ReadXml(filePath);
dataGridView1.DataSource = dataSet1;
dataGridView1.DataMember = "server";
}
Which works great, I have it set exactly how I want it. Now as for the problem, at the moment its just a local file, but i plan to download it live from some website (my own..) eventually..
The problem I have is i want it to update, either manually (user clicking "update") or every so often with a timer.. but i cant seem to get it to work.. I've tried the following code:
Code:
void UpdateSessionList()
{
dataGridView1.Refresh();
string filePath = "SessionsList.xml";
dataSet1.ReadXml(filePath);
dataGridView1.DataSource = dataSet1;
dataGridView1.DataMember = "server";
}
I've also tried, dataSet1.Table.Clear(); they either clear the table and dont re-populate it, or just re-add the same xml data to the table, so it repeats over and over.. can someone please help me out?
Also as a side note, I have a context menu on the GridView that at the moment shows a messagebox, i want it to show say.. the IP of the selected row.. if you get what i mean..
Thanks for your time.
Michael
-
Feb 18th, 2007, 05:46 PM
#2
Re: [2.0] dataGridView + XML
That call to Refresh does not do what you want. The Refresh method of a control simply redraws it on screen. It has nothing whatsoever to do with the data it contains.
Forget the grid. All the grid does is display what's in the DataSet. Just call the Clear method of the DataSet to remove all the existing data then ReadXml to repopulate. The grid will automatically display the new data, which is what data binding is for. Also, if the file name is not changing then it should be declared in one place only, as a class level variable.
-
Feb 18th, 2007, 06:14 PM
#3
Thread Starter
New Member
Re: [2.0] dataGridView + XML
Thanks for your reply, however, it doesnt seem to be working. I load the file on Form1_Load, then i press the update button, (with just the clear() method) which works fine, it clears it and its empty.
But when i add the other code to repopulate the Grid it doesnt seem to reload the XML file. I debug, it loads the file into the grid, great. I change the XML file. Then click the update button, but it doesnt seem to do anything, none of the data i changed in the xml file relfects in the grid.
Did I do something wrong?
Thanks,
Michael
-
Feb 18th, 2007, 06:16 PM
#4
Re: [2.0] dataGridView + XML
Are you saying that no data gets displayed or the data is unchanged? Did you call the DataSet's WriteXml method to save your changes?
-
Feb 18th, 2007, 06:17 PM
#5
Thread Starter
New Member
Re: [2.0] dataGridView + XML
The data is unchanged. And I'm not editing any data within the application. I open the xml file in notepad or wahtever, change some things and save + close. Then click the update button within the application. Nothing seems to change. Restarting the application does however, see the new xml file/information i changed.
-
Feb 19th, 2007, 06:21 PM
#6
Thread Starter
New Member
Re: [2.0] dataGridView + XML
Anybody got any other ideas? It's still not 'updating' the dataGridView, and maybe the dataset? with the "new" information from the xml file.. i just dont get it at all..
Thanks,
Michael
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|