Dim cmbCell As DataGridViewComboBoxCell
Dim isCombo As Boolean
Dim PointTypes As DataTable
Private Function CreateDataColumn(colType As String, name As String, caption As String, [readOnly] As Boolean) As DataColumn
Dim column As New DataColumn()
column.DataType = Type.[GetType](colType)
column.ColumnName = name
column.Caption = caption
column.[ReadOnly] = [readOnly]
Return column
End Function
Private Sub createTable()
Try
'cmbColumn source
PointTypes = New DataTable("point_types")
'create columns
PointTypes.Columns.Add(CreateDataColumn("System.String", "PointType", "Point Type", True))
Dim cmd3 As OleDbCommand = New OleDbCommand("SELECT Songtitle FROM songs ORDER BY songtitle ASC", con)
con.Open()
Dim sdr As OleDbDataReader = cmd3.ExecuteReader
PointTypes.Rows.Add("Select Song...")
While sdr.Read()
PointTypes.Rows.Add(sdr.Item("Songtitle").ToString)
End While
con.Close()
'PointTypes.SelectedIndex = 0
Catch ex As Exception
MessageBox.Show("Error: " & ex.Source & ": " & ex.Message, "Songlist Editor 2 Error !!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Sub
Private Sub AudioCheckBox_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles AudioCheckBox.CheckedChanged
If AudioCheckBox.Checked Then
AudioGrid.Enabled = True
AudioAddEditButton.Enabled = True
createTable()
Try
Dim cmd2 As OleDbCommand = New OleDbCommand("SELECT * FROM Audio", con)
con.Open()
Dim mydat As OleDbDataAdapter = New OleDbDataAdapter(cmd2)
dsOle = New DataSet
mydat.Fill(dsOle, "Audio")
con.Close()
AudioGrid.DataSource = dsOle.Tables("Audio")
Me.AudioGrid.Columns("Id").Visible = False
Me.AudioGrid.Columns("Songtext").Visible = False
Catch ex As Exception
MessageBox.Show("Error: " & ex.Source & ": " & ex.Message, "Songlist Editor 2 Error !!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
Else
AudioGrid.Enabled = False
AudioAddEditButton.Enabled = False
End If
End Sub
Private Sub AudioGrid_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles AudioGrid.CellClick
If e.ColumnIndex = AudioGrid.Columns("Songtitle").Index Then
If cmbCell Is Nothing Then
cmbCell = New DataGridViewComboBoxCell()
cmbCell.DataSource = PointTypes
AudioGrid(e.ColumnIndex, e.RowIndex) = cmbCell
cmbCell.ValueMember = PointTypes.Columns("Songtitle").ColumnName
cmbCell.DisplayMember = PointTypes.Columns("Songtitle").ColumnName
isCombo = True
End If
End If
End Sub
Private Sub AudioGrid_CellValidating(sender As Object, e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles AudioGrid.CellValidating
If e.ColumnIndex = AudioGrid.Columns("Songtitle").Index Then
If isCombo Then
isCombo = False
cmbCell = Nothing
AudioGrid(e.ColumnIndex, e.RowIndex) = New DataGridViewTextBoxCell()
End If
End If
End Sub