How do i add a row to a data source (datagridview)?

dataGridView1.Rows.Add(textBox2.Text, textBox1.Text);

that gives me an error saying:

Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.

my datasource:

XmlDataDocument xmlDatadoc = new XmlDataDocument();
                DataSet ds = new DataSet("Books DataSet");
                ds = xmlDatadoc.DataSet;
                dataGridView1.DataSource = ds.DefaultViewManager;
                dataGridView1.DataMember = "Shortcut";

Unbind it from the dataGridView, add the row, and rebind it.

You need to select "dataTable" instance of DataSet. Use Add method of DataTable's Rows collection.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.