Hello preetham.saroja
i hope ds would help.
i did not use DataGrid instead i used DataGridView.
This is the code...
Private Sub btnFillGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFillGrid.Click
Dim gRow As Integer
'Clear Content of DataGridView
DataGridView1.Rows.Clear()
For gRow = 0 To 9
'Add 10 Records
DataGridView1.Rows.Add()
DataGridView1.Item("dgName", gRow).Value = gRow & " : " & "Sample Data"
DataGridView1.Item("dgAge", gRow).Value = (gRow + 4) * 2
If (gRow Mod 2) Then
DataGridView1.Item("dgSex", gRow).Value = "Male"
Else
DataGridView1.Item("dgSex", gRow).Value = "Female"
End If
Next
End Sub
Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
If DataGridView1.Columns(e.ColumnIndex).Name = "dgSex" Then
If Trim(UCase(DataGridView1.Item("dgSex", e.RowIndex).Value)) = "MALE" Then
e.CellStyle.BackColor = Color.Chocolate
End If
End If
End Sub
Note: I have put DataGridView1 and Commandbutton (btnFillGrid) on my form...