This issue has got to do with saving and retrieving data from xml into DataGridViews and vice versa
My xml file would look like this
As you see above there are sections for Descriptions , CommunicationDescription, TestSteps and TestParamters
For each of the above sections i have a separate data grid view and a separate dataset (ds , ds1, ds2, ds3) in my app. I am able to populate the data grid views properly but i am unable to save the modified datagridview into xml . How should i do this ? And since the data is spread over many data grid views , this is more confusing coz i have many data sets each pertaining to one datagridview.
I made a few changes to the "communicationDescription" and used "ds1.AcceptChanges() ". It did not save . Using WriteXML () did save but the file got completely erased . Check my code .. Dont think it is any where close to correct
| if (ds1.HasChanges() || ds2.HasChanges() || ds3.HasChanges() || ds.HasChanges()) { DescriptionMode mode = (DescriptionMode)Enum.Parse(typeof(DescriptionMode), CurrentNavigation); string[] files = Directory.GetFiles("D:\\TFS\\Code Snippets\\TestController\\TestController\\bin\\Debug\\" + mode.ToString(), "*.xml"); String file = files[overviewClickedRowIndex]; ds1.WriteXml(file); ds2.WriteXml(file); ds3.WriteXml(file); ds.WriteXml(file); } |
Any help will be greatly appreciated. Thanks! Please respond asap..
AVink
anuradha shivPosted Jan 11, 2010, 11:59 PM
My code is attached . The "EditableGridCtrlForTestSteps" and "EditableGridViewCtrlForTestParameters" are the controls in question. The PopulateGrid() function is where i populate the control .
Request u to look into two things :
1. Why i am unable to save the EditableGridCtrlForTestSteps data properly
2. LINQ query to get parameters for a particular test step.
Thanks for the continued help
Also i would like to ask of u to look into my other problem which would be an issue with a LINQ
Nilanka DharmadasaPosted Jan 11, 2010, 6:39 AM
I cannot exactly tell the reason from what you have posted. Can you upload your code? Then I can have a look.
anuradha shivPosted Jan 10, 2010, 10:50 PM
hi niki
A neat sample it was . Helpful no doubt
But there is a small issue. I am able to do exactly wat u said with my first two data grids. But when it comes to the last two , it saves the value i choose , but the file is modified in other parts (Encoding information is modified and some other xml blocks are misplaced) , and the file cant be opened in the app again . How do i overcome this problem , i want to be able to modify only and only the data table i m intending to modify , not the other lines .. As i mentioned i display this data table in the second page of my tabbed control. The ones that i access from the first page work fine . Please help .. I have attached the files before and after the save operation for ur understanding
Thanks for the repeated help
Nilanka DharmadasaPosted Jan 8, 2010, 7:02 AM
You can use a single dataset for all the grid views. Dataset may have multiple datatable which is bound to each datagridview. And you write the whole dataset, even if one datagrid is modified.
Check my sample project.
BTW you should use ReadXml and WRiteXMl methods. Not schema thing.
If you find my answer helpful, please tick 'Do you like this answer' checkbox.
anuradha shivPosted Jan 8, 2010, 5:09 AM
I did not get it done with this ...
I think the problem lies in the data of a single file being distributed over many panes separately . So may be wat i am looking for it partial update / part by part update of the xml file
Rather i would like to restate my problem statement
My problem statement would be this :
I have a Custom Control which is a tabbed panel.
I have an XML doc as my backend to my application
The XML doc has different sections say "Description", "Communication", "Steps" and "Parameters"
Each of these sections i display in 4 different datagridviews on 4 different tabs of the tabbed panel. Hence for each of these sections i have a separate data set -which would be ds1, ds2, ds3 and ds4 respectively;
I am able to populate all the panes properly with doin a ReadXML (filename)
My issue is that i am not able to save sections of the file when i update the respective panes. Only the first pane updates without issues , the rest of them erase my entire xml file when i perform a save .. How should i selectively update the file ? and Since the data of a single file is distributed over many panels , i want to be able to use save button to selectively save the modifications on the currently active pane.
:-) How should i do this ? I read the article "Reading and Writing XML in C#" . But still answers eludes me.
Kirtan PatelPosted Jan 6, 2010, 5:03 AM
ds./span>WriteXmlSchema("Filename.xml"); method instead of WriteXML()
and For retriving DataFrom that Written XML use code like below
DataTable dt = new DataTable();
dt.ReadXmlSchema(" Filename.xml");
DataGridView1.DataSource = dt;