Tugas Praktikum Pemvis 4

download Tugas Praktikum Pemvis 4

of 2

description

a

Transcript of Tugas Praktikum Pemvis 4

Nama: Tri Cahyo SwasonoNIM: J1F114206Shift : 1Tugas: Menu Bar dan DataGridView

Program Data Pelanggan Bakmi CahyoA. Interface Program

B. Coding ProgramKomponenSource Code

hapusprivate 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.

simpanprivate 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.

excel 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); 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.