Question : How do I test for a null value in a datagridview cell

I know how to populate a text box form a datagridviewcell,  but I am having trouble testing for null values in  a datagridview cell.  I've tried several versions of the following but to no avail
 If  row.Cells(4).Value NOT DBNull.Value Then
                    cboTechnologySetType.Text = row.Cells(4).Value.ToString
                End If
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
If dgvTechnologySets.Rows.Count > 0 Then
                Dim rowindex As Integer = dgvTechnologySets.CurrentCell.RowIndex
                Dim row As DataGridViewRow = dgvTechnologySets.Rows(rowindex)
                Dim cell As DataGridViewCell = row.Cells(2)
                Dim strTechCode As String = (cell.Value).ToString
                txtTechnologySetCode.Text = strTechCode
                'if row.Cells(3).Value.ToString != vbNull then
                '    txtTechnologySetName.Text = row.Cells(3).Value.ToString
                'End If
                'If row.Cells(4).Value.ToString = DBNull.Value Then
                '    cboTechnologySetType.Text = row.Cells(4).Value.ToString
                'End If
                If row.Cells(5).Value = True Then
                    chkIsActive.CheckState = CheckState.Checked
                Else
                    chkIsActive.CheckState = CheckState.Unchecked
                End If

            End If

Answer : How do I test for a null value in a datagridview cell

A datagridview textbox cell doesn't have a null value, it have an empty string value: ""

So, if I got you right:

    If dgvTechnologySets.Rows.Count > 0 Then
            Dim rowindex As Integer = dgvTechnologySets.CurrentCell.RowIndex
            Dim row As DataGridViewRow = dgvTechnologySets.Rows(rowindex)
            Dim cell As DataGridViewCell = row.Cells(2)
            Dim strTechCode As String = (cell.Value).ToString
            txtTechnologySetCode.Text = strTechCode
            If row.Cells(3).Value <> "" Then
                txtTechnologySetName.Text = row.Cells(3).Value.ToString
            End If
            If row.Cells(4).Value = "" Then
                cboTechnologySetType.Text = row.Cells(4).Value.ToString
            End If
            If row.Cells(5).Value = True Then
                chkIsActive.CheckState = CheckState.Checked
            Else
                chkIsActive.CheckState = CheckState.Unchecked
            End If

        End If


By the way the not-equal in vb isn't  !=  but  <>
Random Solutions  
 
programming4us programming4us