download gratis video tutorial vb.net plus contoh aplikasi

cara membuat radiobutton dalam datagridview dengan vb.net

 

 

 

Imports System.Data.OleDb


Public Class Form1
Dim ColType(,) As Integer

 

Sub TampilGrid()
On Error Resume Next
DGV.Columns.Clear()
DA = New OleDbDataAdapter("select * from indikator", CONN)
DS = New DataSet
DA.Fill(DS)
DGV.DataSource = DS.Tables(0)
DGV.Columns(0).Visible = False
DGV.Columns(1).Visible = False
DGV.Columns(2).Width = 400
DGV.Columns(2).HeaderText = "Indikator"

Dim Kolom1 As New DataGridViewCheckBoxColumn
DGV.Columns.Add(Kolom1)
Kolom1.HeaderText = "Sangat Kurang"

Dim Kolom2 As New DataGridViewCheckBoxColumn
DGV.Columns.Add(Kolom2)
Kolom2.HeaderText = "Kurang"

Dim Kolom3 As New DataGridViewCheckBoxColumn
DGV.Columns.Add(Kolom3)
Kolom3.HeaderText = "Cukup"

Dim Kolom4 As New DataGridViewCheckBoxColumn
DGV.Columns.Add(Kolom4)
Kolom4.HeaderText = "Baik"

Dim Kolom5 As New DataGridViewCheckBoxColumn
DGV.Columns.Add(Kolom5)
Kolom5.HeaderText = "Sangat Baik"

DGV.Columns.Add("1", "1")
DGV.Columns.Add("2", "2")
DGV.Columns.Add("3", "3")
DGV.Columns.Add("4", "4")
DGV.Columns.Add("5", "5")

For baris1 As Integer = 0 To DGV.RowCount - 1
For kolom As Integer = 8 To DGV.ColumnCount - 1
DGV.Columns(kolom).ReadOnly = True
Next
Next

DGV.Columns(0).ReadOnly = True
DGV.Columns(1).ReadOnly = True
DGV.Columns(2).ReadOnly = True
DGV.DefaultCellStyle.Font = New Font("Microsoft Sans Serif", 10)
For kolom As Integer = 3 To DGV.ColumnCount - 1
DGV.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Next
End Sub

 

Sub Tampilmatakuliah()
CMD = New OleDbCommand("select NAMA_matakuliah from matakuliah", CONN)
DR = CMD.ExecuteReader
cbomatakuliah.Items.Clear()
Do While DR.Read
cbomatakuliah.Items.Add(DR.Item(0))
Loop
End Sub

 

Sub Tampildosen()
CMD = New OleDbCommand("select nama_dosen from dosen", CONN)
DR = CMD.ExecuteReader
cbonamadosen.Items.Clear()
Do While DR.Read
cbonamadosen.Items.Add(DR.Item(0))
Loop
End Sub


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call Koneksi()
Call Tampildosen()
Call Tampilmatakuliah()
Call TampilGrid()
For NILAI As Integer = 1 To 16
ComboBox1.Items.Add(NILAI)
Next
End Sub

 

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbonamadosen.SelectedIndexChanged
CMD = New OleDbCommand("select * from dosen where nama_dosen='" & cbonamadosen.Text & "'", CONN)
DR = CMD.ExecuteReader
DR.Read()
If DR.HasRows Then
lblkodedosen.Text = DR.Item("kode_dosen")
End If
End Sub

 

Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbomatakuliah.SelectedIndexChanged
CMD = New OleDbCommand("select * from matakuliah where nama_matakuliah='" & cbomatakuliah.Text & "'", CONN)
DR = CMD.ExecuteReader
DR.Read()
If DR.HasRows Then
lblkodematakuliah.Text = DR.Item("kode_matakuliah")
End If
End Sub

 

Private Sub DGV_CellEndEdit(ByVal sender As Object, ByVal e As System. Windows. Forms. DataGridViewCellEventArgs) Handles DGV.CellEndEdit
If e.ColumnIndex = 3 Then
DGV.Rows(e.RowIndex).Cells(8).Value = 1
DGV.Rows(e.RowIndex).Cells(9).Value = 0
DGV.Rows(e.RowIndex).Cells(10).Value = 0
DGV.Rows(e.RowIndex).Cells(11).Value = 0
DGV.Rows(e.RowIndex).Cells(12).Value = 0
End If

If e.ColumnIndex = 4 Then
DGV.Rows(e.RowIndex).Cells(8).Value = 0
DGV.Rows(e.RowIndex).Cells(9).Value = 2
DGV.Rows(e.RowIndex).Cells(10).Value = 0
DGV.Rows(e.RowIndex).Cells(11).Value = 0
DGV.Rows(e.RowIndex).Cells(12).Value = 0
End If

If e.ColumnIndex = 5 Then
DGV.Rows(e.RowIndex).Cells(8).Value = 0
DGV.Rows(e.RowIndex).Cells(9).Value = 0
DGV.Rows(e.RowIndex).Cells(10).Value = 3
DGV.Rows(e.RowIndex).Cells(11).Value = 0
DGV.Rows(e.RowIndex).Cells(12).Value = 0
End If

If e.ColumnIndex = 6 Then
DGV.Rows(e.RowIndex).Cells(8).Value = 0
DGV.Rows(e.RowIndex).Cells(9).Value = 0
DGV.Rows(e.RowIndex).Cells(10).Value = 0
DGV.Rows(e.RowIndex).Cells(11).Value = 4
DGV.Rows(e.RowIndex).Cells(12).Value = 0
End If

If e.ColumnIndex = 7 Then
DGV.Rows(e.RowIndex).Cells(8).Value = 0
DGV.Rows(e.RowIndex).Cells(9).Value = 0
DGV.Rows(e.RowIndex).Cells(10).Value = 0
DGV.Rows(e.RowIndex).Cells(11).Value = 0
DGV.Rows(e.RowIndex).Cells(12).Value = 5
End If
End Sub

 

Private Sub DGV_CellMouseClick(ByVal sender As Object, ByVal e As System. Windows .Forms. DataGridViewCellMouseEventArgs) Handles DGV.CellMouseClick
On Error Resume Next
For kolom As Integer = 3 To DGV.Columns.Count - 1
If DGV.Rows(e.RowIndex).Cells(2).Value <> "" Then
DGV.Rows(e.RowIndex).Cells(3).Value = False
DGV.Rows(e.RowIndex).Cells(4).Value = False
DGV.Rows(e.RowIndex).Cells(5).Value = False
DGV.Rows(e.RowIndex).Cells(6).Value = False
DGV.Rows(e.RowIndex).Cells(7).Value = False
End If
Next
End Sub

 

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System. Windows. Forms. KeyPressEventArgs) Handles ComboBox1.KeyPress
If Not (e.KeyChar >= "0" And e.KeyChar <= "9" Or e.KeyChar = vbBack) Then
e.Handled = True
End If
End Sub

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Try
For baris As Integer = 0 To DGV.RowCount - 2
Dim simpan As String = "insert into evaluasi values('" & DateTimePicker1.Text & "','" & cbonamadosen.Text & "','" & txtkelas.Text & "','" & cbomatakuliah.Text & "','" & ComboBox1.Text & "','" & DGV.Rows(baris).Cells(1).Value & "','" & DGV.Rows(baris).Cells(2).Value & "','" & DGV.Rows(baris).Cells(8).Value & "','" & DGV.Rows(baris).Cells(9).Value & "','" & DGV.Rows(baris).Cells(10).Value & "','" & DGV.Rows(baris).Cells(11).Value & "','" & DGV.Rows(baris).Cells(12).Value & "','" & txtsaran.Text & "')"
CMD = New OleDbCommand(simpan, CONN)
CMD.ExecuteNonQuery()
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call TampilGrid()
End Sub

 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
End Class