I want to open a txt file with OpenFileDialog and add it to an datagridview in windows form.
I also want to use BindingSource because I have to add new data to the existing and loaded datagridview txt file from another Form using a button and some textboxes and the data given by the user in the textbox should be added to the datagridview to the existing txt file.
Here is my code of the input button event but I have no idea how to get started with another form and binding the data
public void input_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
DataTable dt = new DataTable("TableName");
//Set the Columns or fill it with a DataAdapter
dt.Columns.Add("ID", typeof(string));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Display", typeof(string));
dt.Columns.Add("Color", typeof(string));
dt.Columns.Add("Capacity", typeof(string));
dt.Columns.Add("Processor", typeof(string));
dt.Columns.Add("Operation System", typeof(string));
dt.Columns.Add("Released", typeof(string));
dgvBindingSource = new BindingSource();
dgvBindingSource.DataSource = dt;
datagridview.DataSource = dgvBindingSource;
dt.Dispose();
}
Looks like this is what you're looking for