I want to add a row from multiple textbox, a datetimepicker and a combobox (form2) to datagridview (form1). If i try to add the row it won't add up. What i really want is to have an integrated autosave/autoload and i want to create a blank datagridview with only the columns so the user can manually add the rows of data. i will explain a little bit more about what i'm building here; Form1: will have a datagridview (to store some user added data), 3 textboxes (textbox1 = total amount of column[5], textbox2 = total amount of column[5] where column[6] is "Nee", textbox3 = textbox1 - textbox2) and a button to open form2; Form2: Will have 1 datetimepicker, 5 textboxes, 1 combobox and a button wich will add the datetimepicker, 5 textboxes and combobox as a new row in the datagridview. i also want the data to be autosaved and autoload when closing and opening the progam. this is what i got so far:
program:
using System;
using System.Windows.Forms;
namespace Javell_Administratie_Software
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run (new Overzicht());
}
}
}
form1:
using System;
using System.Data;
using System.Windows.Forms;
namespace Javell_Administratie_Software
{
public partial class Overzicht : Form
{
public Overzicht()
{
InitializeComponent();
dt = table;
Overzicht1.DataSource = dt;
}
public DataTable dt = new DataTable();
public DataSet ds = new DataSet();
public DataTable table
{
set
{
foreach (DataGridViewColumn col in Overzicht1.Columns)
{
dt.Columns.Add(col.Name);
col.DataPropertyName = col.Name;
}
ds.Tables.Add(dt);
}
get
{
return dt;
}
}
public void AddDataTableRow()
{
Toevoegen tv = new Toevoegen();
object row = new object[]
{
tv.dateTimePicker1.Value, tv.textBox1.Text,
tv.textBox2.Text, tv.textBox3.Text, tv.textBox4.Text,
tv.textBox5.Text, tv.comboBox1.Text
};
dt.Rows.Add(row);
Overzicht1.DataSource = dt;
Overzicht1.Update();
tv.Close();
}
public void Toevoegen1_Click(object sender, EventArgs e)
{
Toevoegen tv = new Toevoegen();
tv.Show();
}
}
}
form2:
using System;
using System.Windows.Forms;
namespace Javell_Administratie_Software
{
public partial class Toevoegen : Form
{
public Toevoegen()
{
InitializeComponent();
}
public void Toevoegen2_Click(object sender, EventArgs e)
{
Overzicht oz = new Overzicht();
oz.AddDataTableRow();
oz.Overzicht1.DataSource = oz.dt;
oz.Overzicht1.Update();
this.Close();
}
}
}