Hi Ive searched many topics, also here in stackoverflow, however none solved my problem
This is my main form where I operate with my database and display items in datagridview
public partial class Form1 : Form
{
DatabaseConnection objConnect;
string conString;
private static DataTable table;
DataSet dataSet;
public Form1()
{
InitializeComponent();
CreateConnection();
MakeDataTable();
}
public DataTable table
{
get
{
return table;
}
}
private void MakeDataTable()
{
table = new DataTable();
DataColumn column;
column = new DataColumn();
column.DataType = Type.GetType("System.String");
column.ColumnName = "Name of Item";
table.Columns.Add(column);
etc...
}
//this connects to my local db through DatabaseConnection.cs
//where I got table ItemsInWorld,
//from where I take items and add it via InputBox to my datatable table
//which works fine and shows all added items
private void CreateConnection()
{
objConnect = new DatabaseConnection();
conString = Properties.Settings.Default.ItemsConnectionString;
objConnect.connection_string = conString;
objConnect.Sql = Properties.Settings.Default.SQL;
dataSet = objConnect.GetConnection;
}
//I also have here code that show content of this DataTable table in
//DataGridView Form1.dataGridView
}
Lets say I would click on button in Form1, then Form2 would appear with another dataGridView
In this form, as I said, I would like to have another dataGridView lets call it just dataGridV that would show same items as the dataGridView in Form1, what should I do?
This is my code yet, but it only shows empty table
Form2 : form
{
DataTable table2;
DatabaseConnection objConnect;
string conString;
DataSet dataSet;
public DataGridV()
{
InitializeComponent();
CreateConnection();
CreateDataView();
}
private void CreateConnection()
{
objConnect = new DatabaseConnection();
conString = Properties.Settings.Default.ItemsConnectionString;
objConnect.connection_string = conString;
objConnect.Sql = Properties.Settings.Default.SQL;
dataSet = objConnect.GetConnection;
}
public void CreateDataView()
{
Form1 f = new Form1();
table2 = f.TableBackpack;
dataGridViewMix.DataSource = new DataView(tableBackpack);
}
}