Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,
I want to add the contents of a textBox and DataGridView into an XML file together and then again load it back to the same.
I know how to add them separately but cannot achieve this.
This is how i was adding the datagridview and to the same i want to append the contents of the textbox
C#
DataTable dt = new DataTable();
            foreach (DataGridViewColumn col in dgvIsland.Columns)
            {
                dt.Columns.Add(col.HeaderText);
            }
            foreach (DataGridViewRow row in dgvIsland.Rows)
            {
                DataRow dRow = dt.NewRow();
                foreach (DataGridViewCell cell in row.Cells)
                {
                    dRow[cell.ColumnIndex] = cell.Value;
                }
                dt.Rows.Add(dRow);
            }
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            ds.WriteXml(filename);

Please help!!!
Thanks
Posted

1 solution

After the for loop, which you are doing for DataGridView Rows, just add another Row to the DataTable dt.
Then for that Row, in some column, add the TextBox value.
C#
DataRow newTextBoxRow = dt.NewRow();

newTextBoxRow["someColumnName"] = txtYourTextBox.Text;
 
Share this answer
 
Comments
sovit agarwal 9-Jun-14 2:22am    
I dont want to append the value of a textBox to the datagridview...i want both the vales separately

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900