Anda di halaman 1dari 2

Nama

NIM
Shift
Tugas

: Tri Cahyo Swasono


: J1F114206
:1
: Menu Bar dan DataGridView

Program Data Pelanggan Bakmi Cahyo


A. Interface Program

B. Coding Program
Komponen

hapus

simpan

Source Code
private void hapus_Click(object sender,
EventArgs e)
{
{
foreach (DataGridViewCell
oneCell in dataGridView1.SelectedCells)
{
if (oneCell.Selected)
dataGridView1.Rows.RemoveAt(oneCell.RowIndex);
}
}
} //source code ini digunakan untuk
menghapus data perbaris.
private void simpan_Click(object sender,
EventArgs e)
{
string[] row = new string[]
{ txtnama.Text, txtnohp.Text, txtnbakfav.Text,
txtkelamin.Text, txtpekerjaan.Text,z };
dataGridView1.Rows.Add(row);

txtnama.Clear();
txtnohp.Clear();
txtnbakfav.Clear();
txtkelamin.Clear();
txtpekerjaan.Clear();
} // source code ini digunakan untuk
menyimpan data yang diinputkan pada textbox
yang terdiri dari nama, kelamin, no.hp, bakmi
favorit, dan pekerjaan.
private void excel_Click(object sender,
EventArgs e)
{
Microsoft.Office.Interop.Excel._Application app
= new
Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel._Workbook
workbook = app.Workbooks.Add(Type.Missing);

excel

Microsoft.Office.Interop.Excel._Worksheet
worksheet = null;
app.Visible = true;
worksheet =
workbook.Sheets["Sheet1"];
worksheet = workbook.ActiveSheet;
worksheet.Name = "Exported from
gridview";
for (int i = 1; i <
dataGridView1.Columns.Count + 1; i++)
{
worksheet.Cells[1, i] =
dataGridView1.Columns[i - 1].HeaderText;
}
for (int i = 0; i <
dataGridView1.Rows.Count - 1; i++)
{
for (int j = 0; j <
dataGridView1.Columns.Count; j++)
{
worksheet.Cells[i + 2, j +
1] =
dataGridView1.Rows[i].Cells[j].Value.ToString()
;
}
}
app.Quit();
} // source code ini digunakan untuk
mengekspor data inputan yang ada pada
datagridview ke file excel.

Anda mungkin juga menyukai