Socarsky
Well-known member
I am tracking of below to add a comboBox in DataGridView, I am still searching to find a good one for me. I only fill a comboBox with data from ms sql and type a couple cells then records all cells into ms sql. My laptop's SQL Server does not work on WiFi and I cannot try below but I could only type them... Let me try it tomorrow when I go to company. That's why I am not sure below code whether is suit.
VB.NET:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
cmbBox = New ComboBox
cmbBox.Visible = False
DataGridView1.Controls.Add(cmbBox)
VB.NET:
Private Sub DataGridView1_CellBeginEdit(sender As Object, e As DataGridViewCellCancelEventArgs) Handles DataGridView1.CellBeginEdit
Try
If ((DataGridView1.Focused) OrElse (DataGridView1.CurrentCell.ColumnIndex = 4)) Then
cmbBox.Location = DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, False).Location
cmbBox.Visible = True
If (DataGridView1.CurrentCell.Value IsNot DBNull.Value) Then
cmbBox.SelectedValue = DataGridView1.CurrentCell.Value
Else
cmbBox.SelectedValue = DateTime.Today.ToString
End If
Else
cmbBox.Visible = False
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
VB.NET:
Private Sub DataGridView1_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
Try
If ((DataGridView1.Focused) OrElse (DataGridView1.CurrentCell.ColumnIndex = 4)) Then
DataGridView1.CurrentCell.Value = cmbBox.SelectedValue
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub