I am a beginner in c#. I have a XML file (xmlfile.xml) which has some text in it.
On Form Load Event I am reading the XML file and showing it in datagridview1 of mainForm Form.
I am using below code to do this
DataSet ds = new DataSet();
ds.ReadXml(@"D:\xmlfile.xml");
dataGridView1.DataSource = ds.Tables[0].DefaultView;
dataGridView1.Tag = ds; /* TAG */
I have another form noteForm in which I have textBox1 and btnSub button. Whenever the user clicks on btnSub button textBox1.Text should be added to the dataGridView1 of the mainForm
I am trying the below code to do this
string strTitle;
string[] row = new string[] { strTitle, DateTime.Now.ToString("M/d/y"), "checked" };
_parent.dataGridView1.Tag.Tables[0].Rows.Add(row);
_parent.dataGridView1.Rows.Add();
_parent.dataGridView1.DataSource = _parent.dataGridView1.Tag.Tables[0].DefaultView;
The above code is showing error — “Rows cannot be programmatically added to the DataGridView’s rows collection when the control is data-bound.”
I cant understand what is this error. Please help.
_parent is just mainForm form in noteForm
Add new row to your DataSet
dsnot todataGridView1EDIT