I have a datagridviewcomboboxcolumn that I am populating this way :
I am doing the following code so that there is no blank in the first line of the combobox where the user is in edit mode. If I don't do this, there is a blank line, followed by the value previously chosen, followed by the rest of the table.Code:'--------------------------------------------------------------------- ' If person is editing a record, their previous choice should always be the first ' in the list '--------------------------------------------------------------------- If intNameKey <> 0 Then strSql = "select '1' as sort_seq, name_key, species from species " & _ "where name_key = " & intNameKey & " " & _ " and upper(name_type) = 'FISH' " & _ "union " & _ "select '2' as sort_seq, name_key, species from species " & _ "where name_key <> " & intNameKey & " " & _ " and upper(name_type) = 'FISH' " & _ "order by sort_seq, species" End If '--------------------------------------------------------------------- ' If person is adding a record, show fish in alpha order. '--------------------------------------------------------------------- If intNameKey = 0 Then strSql = "select '1' as sort_seq, name_key, species from species " & _ "where upper(name_type) = 'FISH' order by species" End If objDA = New SqlDataAdapter(strSql, objConn) objDS = New DataSet objDA.Fill(objDS, "species") objConn.Close() With Me.cboSpecies (defined as a datagridviewcomboboxcolumn) .DataSource = objDS.Tables("species") .DisplayMember = "species" .ValueMember = "name_key" .DataPropertyName = "name_key" End With strSpecies = objDS.Tables("species").Rows(0).Item(2).ToString
Loading the data works fine. My problem is that if the user doesn't make any changes and hits the <UPDATE> button, when I loop thru each line of the datagridview, I can't seem to get the value (name_key) behind the cboSpecies. Here is what I am using :Code:Private Sub dgvFish_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgvFish.CellFormatting If e.ColumnIndex = Me.dgvFish.Columns(intSpeciesCol).Index And e.RowIndex >= 0 Then Dim d As DataGridViewComboBoxCell = Me.dgvFish.Rows(e.RowIndex).Cells(e.ColumnIndex) If e.Value = Nothing And d.Items.Count > 0 Then e.Value = strSpecies End If End If End Sub
Me.dgvFish.Rows(intRowIdx).Cells(3).Value to try to get the value. Any help would be greatly appreciated.




Reply With Quote