I have a DataGridViewComboBoxColumn that works and populates well. All I want to know is how to add a blank field. This way if the user inadvertently selects something they can select the blank row rather than pressing Ctrl-0.
In my code I tried adding Items.Add(DBNull.Value) but to no avail, as shown in my code. All it does is give me an error which is why it is rem'd out.
Any ideas would be greatly appreciated.
Private Sub FillCombobox(strHeaderText As String, strPropertyName As String, strTableName As String)
Using cboBox As New DataGridViewComboBoxColumn
With cboBox
.HeaderText = strHeaderText
.DataPropertyName = strPropertyName
.DataSource = GetData("Select * From " & strTableName)
.ValueMember = .DataPropertyName
'.Items.Add(DBNull.Value)
End With
dgrMain.Columns.Add(cboBox)
End Using
End Sub
EDIT
Private Function GetData(ByVal sqlCommand As String) As DataTable
Dim da = New OleDbDataAdapter(sqlCommand, strConn)
Dim con As New OleDbConnection(strConn)
con.Open()
Dim command As OleDbCommand = New OleDbCommand(sqlCommand, con)
da.SelectCommand = command
Dim dt As DataTable = New DataTable()
da.Fill(dt)
con.Close()
Return dt
End Function