private void to_print(DataGridView dgv) { FRM_PRINT frmPrint = new FRM_PRINT(); //frmPrint.dataGridView1 //create table with three columns DataTable t = new DataTable(); t.Columns.Add("ID", typeof(string)); t.Columns.Add("FULL NAME", typeof(string)); t.Columns.Add("POSITION", typeof(string)); t.Columns.Add("OFFICE", typeof(string)); //add data to table for (int i = 0; i < dgv.RowCount; i++) { string[] arrVals = new string[4]; arrVals[0] = dgv.Rows[i].Cells[0].Value.ToString(); arrVals[1] = dgv.Rows[i].Cells[1].Value.ToString(); arrVals[2] = dgv.Rows[i].Cells[2].Value.ToString(); arrVals[3] = dgv.Rows[i].Cells[3].Value.ToString(); t.Rows.Add(arrVals); } //bind table to datagridview frmPrint.dataGridView1.DataSource = t; frmPrint.ShowDialog(); }
private void save_to_print(DataGridView dgv) { string listEmps = ""; for (int i = 0; i < dgv.RowCount; i++) { //string theID = dgv.Rows[i].Cells["ID"].ToString(); if (i >= dgv.RowCount - 1) { listEmps += dgv.Rows[i].Cells["ID"].Value.ToString(); } else { listEmps += dgv.Rows[i].Cells["ID"].Value.ToString() + ":"; } } int last_id; using (SqlConnection conn = new SqlConnection(Global.connStr)) { string stmt = "insert into tblTest (test_event_code, test_employees) OUTPUT INSERTED.test_event_id values (@test_event_code, @test_employees)"; using (SqlCommand comm = new SqlCommand(stmt, conn)) { comm.Parameters.Add("@test_event_code", SqlDbType.VarChar, 50).Value = "00001"; comm.Parameters.Add("@test_employees", SqlDbType.Text).Value = listEmps; conn.Open(); last_id = Convert.ToInt32(comm.ExecuteScalar()); conn.Close(); conn.Dispose(); comm.Dispose(); } } Global.print_test_id = last_id; FRM_PRINT frmPrint = new FRM_PRINT(); frmPrint.ShowDialog(); }
private void btnMDPrint_Click(object sender, EventArgs e) { FRM_PRINT frmPrint = new FRM_PRINT(); frmPrint.ShowDialog(this); }