将datagriview值转换为字符串

时间:2016-12-21 21:14:30

标签: vb.net datagridview

我一直在尝试这么多方法,但没有任何工作。它看起来很简单,我的脑袋即将爆炸。我需要的是在我的datagridview(dgvLocation)值<>时显示标签(Sales1)。没有。这就是我所拥有的:

lblSales.Text = dgvLocation.Rows(0).Cells(1).value

If lblSales.Text <> nothing then 
    Sales1.Visible = true
End If

3 个答案:

答案 0 :(得分:0)

代码应如下所示:

Sales1.Visible = dgvLocation.Rows(0).Cells(1).value.ToString Is Not Nothing

答案 1 :(得分:0)

您必须使用String.IsNullOrEmpty方法并检查值Is Not Nothing

If Not dgvLocation.Rows(0).Cells(1).value Is Nothing AndAlso Not String.IsNullOrEmpty(lblSales.Text.Trim) Then

LblSales.Text = dgvLocation.Rows(0).Cells(1).value.Tostring

Sales1.Visible = True

End If

答案 2 :(得分:0)

当对象为"@angular/common": "^2.3.1", "@angular/compiler": "^2.3.1", "@angular/core": "^2.3.1", 时,

Object.ToString会抛出NullReferenceException 要将引用类型转换为String,请改用Nothing

检查值是否不是Convert.ToString(Object)

Nothing

检查值是否为Sales1.Visible = dgvLocation(1, 0).Value IsNot Nothing Nothing""

DbNull.Value
相关问题