-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm3.cs
More file actions
80 lines (72 loc) · 2.68 KB
/
Form3.cs
File metadata and controls
80 lines (72 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ProductTrackingSystem
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Add(textBox7.Text, textBox2.Text, textBox3.Text, textBox8.Text, textBox4.Text, textBox6.Text);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
excel.Visible = true;
Microsoft.Office.Interop.Excel.Workbook workbook = excel.Workbooks.Add(System.Reflection.Missing.Value);
Microsoft.Office.Interop.Excel.Worksheet sheet1 = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets[1];
int startCol = 1;
int startRow = 1;
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[startRow, startCol + i];
myRange.Value2 = dataGridView1.Columns[i].HeaderText;
}
startRow++;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[startRow + i, startCol + j];
myRange.Value2 = dataGridView1[j, i].Value == null ? "" : dataGridView1[j, i].Value;
}
}
}
private void button3_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count != 0)
{
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
dataGridView1.Rows.Remove(row);
}
}
private void button4_Click(object sender, EventArgs e)
{
Form1 form1 = new Form1();
form1.Show();
this.Close();
}
private void button5_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}