I'm developing a basic Game Launcher and I'm running into an error as show below... the error states that "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."
what can i do to resolve this issue?
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show();
}
CODE FROM ANOTHER FORM:
MainForm mainForm;
DataTable table;
public Form2(MainForm mf)
{
InitializeComponent();
this.mainForm = mf;
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Exe Files (.exe)|*.exe|All Files (*.*)|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtPath.Text = openFileDialog1.FileName;
}
}
private void button2_Click(object sender, EventArgs e)
{
DataTable dataTable = (DataTable)dataGridView1.DataSource;
DataRow drToAdd = dataTable.NewRow();
drToAdd["Game"] = txtTitle;
drToAdd["Path"] = txtPath;
mainForm.dataGridView1.Rows.Add(drToAdd);
dataTable.AcceptChanges();
}
private void AddGame_Load(object sender, EventArgs e)
{
table = new DataTable();
table.Columns.Add("Game", typeof(string));
table.Columns.Add("Path", typeof(string));
dataGridView1.DataSource = table;
dataGridView1.Columns["Path"].Visible = false;
dataGridView1.Columns["Game"].Width = 138;
dataGridView1.ScrollBars = ScrollBars.None;
}
}