none
How to write new line on resource file. RRS feed

  • Question

  • Hello Everyone,
     
    Can you please help me add new row on resource file, here is the code i have used to read my resource file.
    I have no idea on how to add new line... Please help 
     
     
    private void btnBrowse1_Click(object sender, EventArgs e)
    {
     
    BrowseFile();
    //versionIncrement();
    if (txtInputfile.Text.Length > 0)
    {
    PathSelection = txtInputfile.Text;
    }
    oDataSet = new DataSet();
    //now am reading the files fro the path that is selected
    XmlReadMode omode = oDataSet.ReadXml(PathSelection);
    for (int i = 0; i < oDataSet.Tables[2].Rows.Count; i++)
    {
    string comment = oDataSet.Tables["data"].Rows[i][2].ToString();
    //the elements array contain all the columns filled
    string[] elements = comment.Split('-'); //when it reaches the comma, it will jump to the next line
    string font = elements[0]; //Font
    string datestamp = elements[1]; //DateStamp
    string commentVal = elements[2]; //Comment
    string[] row = new string[] { oDataSet.Tables["data"].Rows[i][0].ToString(), oDataSet.Tables["data"].Rows[i][1].ToString(), font, datestamp = DateTime.Now.ToString(), commentVal };
    Gridview_Input.Rows.Add(row);
    Wednesday, February 4, 2015 10:37 AM

Answers

  • Add a DataGridview to the form and use code below.  It will automatically add the data

    XmlReadMode omode = oDataSet.ReadXml(PathSelection);
    datagridview1.DataSource =  oDataSet.Tables[2];

    Then add new row to DataTable.

    DataRow newRow = oDataSet.Tables[2].Rows.Add();


    jdweng

    Wednesday, February 4, 2015 10:48 AM
  • Hello Sitholimela,

    >> Can you please help me add new row on resource file, here is the code i have used to read my resource file.

    From your description, it seems that your resource file is a XML format file, if so, you could also have a try to use LINQ To XML which is easy to operate the XML file to add new row to your resource file, and here is an example to show how to add a new element/row to the specific tree:

    Linq to XML Add element to specific sub tree

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, February 5, 2015 3:02 AM
    Moderator

All replies

  • Add a DataGridview to the form and use code below.  It will automatically add the data

    XmlReadMode omode = oDataSet.ReadXml(PathSelection);
    datagridview1.DataSource =  oDataSet.Tables[2];

    Then add new row to DataTable.

    DataRow newRow = oDataSet.Tables[2].Rows.Add();


    jdweng

    Wednesday, February 4, 2015 10:48 AM
  • I tried this and it is not working;

    private void Gridview_Output_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                try
                {
                    XmlReadMode omode = oDataSet.ReadXml(PathSelection);
                    Gridview_Output.DataSource = oDataSet.Tables[2];
                    DataRow newRow = oDataSet.Tables[2].Rows.Add();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error occured.\nError message: " + ex.Message, "Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

    Wednesday, February 4, 2015 10:58 AM
  • I think you left out the following :

    oDataSet = new DataSet();


    jdweng

    Wednesday, February 4, 2015 12:24 PM
  • Hello Sitholimela,

    >> Can you please help me add new row on resource file, here is the code i have used to read my resource file.

    From your description, it seems that your resource file is a XML format file, if so, you could also have a try to use LINQ To XML which is easy to operate the XML file to add new row to your resource file, and here is an example to show how to add a new element/row to the specific tree:

    Linq to XML Add element to specific sub tree

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, February 5, 2015 3:02 AM
    Moderator