1: #Region "Form's Events"
2: Private Sub ControlInDataGrid_Load(ByVal sender As System.Object, _
3: ByVal e As System.EventArgs) Handles MyBase.Load
4: Me.CreateControlInDataGrid()
5: Me.FillDataToCombo()
6: Me.CreateDataSource()
7: Me.MyDataGridStyle()
8: End Sub
9: #End Region
10:
11: #Region "CommandButton's Events"
12: Private Sub Button1_Click(ByVal sender As System.Object, _
13: ByVal e As System.EventArgs) Handles Button1.Click
14: '//save
15: Try
16: 'update data
17: daProducts.Update(dsProducts.Tables(0))
18:
19: 'refresh data
20: Me.FillDataToCombo()
21: Me.CreateDataSource()
22: Me.MyDataGridStyle()
23:
24: MsgBox("Updated")
25: Catch ex As Exception
26: Me.dsProducts.Tables(0).RejectChanges()
27: MsgBox(ex.Message)
28: End Try
29: End Sub
30:
31: Private Sub Button2_Click(ByVal sender As System.Object, _
32: ByVal e As System.EventArgs) Handles Button2.Click
33: '//batal
34: Me.dsProducts.Tables(0).RejectChanges()
35: End Sub
36: #End Region
37:
38: #Region "Combo CategoryID Events"
39: Private Sub cboCategoryID_MouseEnter(ByVal sender As Object, _
40: ByVal e As System.EventArgs) Handles cboCategoryID.MouseEnter
41: Try
42: 'categoryid ada di kolom 3 (index dimulai dari 0)
43: Dim currentID As String = DataGrid1.Item( _
44: Me.DataGrid1.CurrentRowIndex, 3).ToString.Trim
45:
46: Dim intIndex As Integer = cboCategoryID.FindString(currentID)
47: Me.cboCategoryID.SelectedIndex = intIndex
48: Catch ex As Exception
49: End Try
50: End Sub
51:
52: Private Sub cboCategoryID_SelectedIndexChanged(ByVal sender As Object, _
53: ByVal e As System.EventArgs) Handles _
54: cboCategoryID.SelectedIndexChanged
55: If Me.cboCategoryID.Text <> "" Then
56: Me.DataGrid1.Item(Me.DataGrid1.CurrentRowIndex, 3) = _
57: Me.cboCategoryID.Text
58: End If
59: End Sub
60: #End Region
61:
62: #Region "Combo SupplierID Events"
63: Private Sub cboSupplierID_MouseEnter(ByVal sender As Object, _
64: ByVal e As System.EventArgs) Handles cboSupplierID.MouseEnter
65: Try
66: 'supplierid ada di kolom 2 (index dimulai dari 0)
67: Dim currentID As String = DataGrid1.Item( _
68: DataGrid1.CurrentRowIndex, 2).ToString
69: Dim intIndex As Integer = cboSupplierID.FindString(currentID)
70: Me.cboSupplierID.SelectedIndex = intIndex
71: Catch ex As Exception
72: End Try
73: End Sub
74:
75: Private Sub cboSupplierID_SelectedIndexChanged(ByVal sender As Object, _
76: ByVal e As System.EventArgs) Handles cboSupplierID.SelectedIndexChanged
77: If Me.cboSupplierID.Text <> "" Then
78: DataGrid1.Item(DataGrid1.CurrentRowIndex, 2) = _
79: cboSupplierID.Text
80: End If
81: End Sub
82: #End Region
83:
84: #Region "DataGrid's Events"
85: Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, _
86: ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
87: Try
88: Dim currentID As String = DataGrid1.Item( _
89: DataGrid1.CurrentRowIndex, 2).ToString
90:
91: Dim intIndex As Integer = cboSupplierID.FindString(currentID)
92: cboSupplierID.SelectedIndex = intIndex
93:
94: currentID = DataGrid1.Item(DataGrid1.CurrentRowIndex, 3).ToString
95: intIndex = cboCategoryID.FindString(currentID)
96: cboCategoryID.SelectedIndex = intIndex
97: Catch ex As Exception
98: End Try
99: End Sub
100: #End Region