0

I have asked this question yesterday and i didn't get good response. i am working on a resx file. I have read the file and load it on data-gridview. now i wanted to be able to edit from the file and save.I have tried many ways but i didn't come with the solution. yesterday i tried this code below. I don't know how i can edit. please help me.

   private void btnSave_Click(object sender, EventArgs e)
    {
            foreach (DataGridViewRow _row in Gridview_Output.Rows)
            {
                DataRow dt1 = oDataTable.NewRow();
                for (int i = 0; i < Gridview_Output.ColumnCount; i++)
                {
                    Gridview_Input.SelectedRows[0].Cells[1].Value = oDataSet.Tables["data"].Rows[0][1].ToString();
                    Gridview_Input.SelectedRows[0].Cells[2].Value = oDataSet.Tables["data"].Rows[0][2].ToString();
                    Gridview_Input.SelectedRows[0].Cells[3].Value = oDataSet.Tables["data"].Rows[0][3].ToString();
                    Gridview_Input.SelectedRows[0].Cells[4].Value = oDataSet.Tables["data"].Rows[0][4].ToString();
                    oDataTable.Rows.Add(dt1);
                }
                oDataSet.Tables.Add(oDataTable);
                oDataSet.WriteXml(PathSelection);
            }
Kurubaran
  • 8,696
  • 5
  • 43
  • 65
IT Forward
  • 367
  • 2
  • 7
  • 28
  • Do you want to change only datatable value or save the resx also ? – Rohit Prakash Feb 10 '15 at 07:10
  • edit the value inside the resx file and save the changes. example i have a column for comment, i want the user to click from the comment column and edit then click same. the changes must also apply on the file – IT Forward Feb 10 '15 at 07:17

1 Answers1

0

This will help you almost the way you want it.
Code snippet from Modifying .resx file in c#

public static void UpdateResourceFile(Hashtable data, String path)
{
    Hashtable resourceEntries = new Hashtable();

    //Get existing resources
    ResXResourceReader reader = new ResXResourceReader(path);
    if (reader != null)
    {
        IDictionaryEnumerator id = reader.GetEnumerator();
        foreach (DictionaryEntry d in reader)
        {
            if (d.Value == null)
                resourceEntries.Add(d.Key.ToString(), "");
            else
                resourceEntries.Add(d.Key.ToString(), d.Value.ToString());
        }
        reader.Close();
    }

    //Modify resources here...
    foreach (String key in data.Keys)
    {
        if (!resourceEntries.ContainsKey(key))
        {

            String value = data[key].ToString();
            if (value == null) value = "";

            resourceEntries.Add(key, value);
        }
    }

    //Write the combined resource file
        ResXResourceWriter resourceWriter = new ResXResourceWriter(path);

        foreach (String key in resourceEntries.Keys)
        {
            resourceWriter.AddResource(key, resourceEntries[key]);
        }
        resourceWriter.Generate();
        resourceWriter.Close();

}
Community
  • 1
  • 1
Rohit Prakash
  • 1,975
  • 1
  • 14
  • 24