Dear All Master,
I Want to display message for particular rows with list item column value is null or blank in datagridview.
so I want to display the message from the list item of "column1" where the null and blank. Is there a recommended solution that is best?
Thanks
so the output should be like this :
The following rows, Column2 must have a value.
from list item column1 :
A1
A3
A5
A6
A7
or
A1,A3,A5,A6,A7
Please check
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.Rows.Add(New Object() {"A1", Nothing, "C1"})
DataGridView1.Rows.Add(New Object() {"A2", "B2", "C2"})
DataGridView1.Rows.Add(New Object() {"A3", Nothing, "C3"})
DataGridView1.Rows.Add(New Object() {"A4", "B4", "C4"})
DataGridView1.Rows.Add(New Object() {"A5", 0, "C5"})
DataGridView1.Rows.Add(New Object() {"A6", 0, "C6"})
DataGridView1.Rows.Add(New Object() {"A7", Nothing, "C7"})
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Results =
(
From T In DataGridView1.Rows.OfType(Of DataGridViewRow) _
.Select(Function(r, i) New With
{
.Item = r,
.Index = i
})
Where Not T.Item.IsNewRow AndAlso IsNothing(T.Item.Cells("Column2").Value)
).ToList
If Results.Count > 0 Then
MessageBox.Show("The following rows, Column2 must have a value." &
Environment.NewLine &
String.Join(",", Results.Select(Function(x) x.Index).ToArray))
Else
'
' Column2 has values for each row
'
End If
End Sub
End Class