i'm using VB.NET. and its a windows application.
in my program i need to display a table in datagrid. so i created the table using DataTable and i'm calling that dataTable to dataGrid. and its working fine...
but according to one of the field in that table i need to change the back color of that row. one of the field in that table called "Active", it will have value as True or False. so if Active =True then i need that corresponding row to be turned Pink. and if Active = False then i need that corresponding row to be white.
and i search lots in net... but didnt get much help at all...
this the code i'm using now to create table and displaying it inside Datagrid.
how can i change the back color of rows in DataGrid when Active=True... and i need to change only that particular row's back color were Active=True...
if you have any idea how to do this please help me... and if you can provide an example, then it will be great help for me...
thanks in advance.
in my program i need to display a table in datagrid. so i created the table using DataTable and i'm calling that dataTable to dataGrid. and its working fine...
but according to one of the field in that table i need to change the back color of that row. one of the field in that table called "Active", it will have value as True or False. so if Active =True then i need that corresponding row to be turned Pink. and if Active = False then i need that corresponding row to be white.
and i search lots in net... but didnt get much help at all...
this the code i'm using now to create table and displaying it inside Datagrid.
VB.NET:
Dim Table1 As DataTable = New DataTable("Orders")
Dim Row As DataRow
Dim EmpName As DataColumn = New DataColumn("EmpName")
Table1.Columns.Add(EmpName)
Dim EmployeeID As DataColumn = New DataColumn("EmpID")
EmployeeID.DataType = System.Type.GetType("System.Int32")
Table1.Columns.Add(EmployeeID)
Dim CardNo As DataColumn = New DataColumn("CardNo")
CardNo.DataType = System.Type.GetType("System.Int32")
Table1.Columns.Add(CardNo)
Dim Active As DataColumn = New DataColumn("Active")
Table1.Columns.Add(Active)
Dim i As Integer = 0
Dim strSQL As String = "Select LastName, FirstName, EmpID, CardNo, Active from Employees order by LastName asc"
myConnection.Open()
Dim myCommand As New OleDbCommand(strSQL, myConnection)
Dim myReader As OleDbDataReader = myCommand.ExecuteReader
While myReader.Read
Row = Table1.NewRow()
Row("EmpName") = myReader(0) & "," & myReader(1)
Row("EmpID") = myReader(2)
Row("Card No") = myReader(3)
If myReader(4) = 0 Then
Row("Active") = "True"
ElseIf myReader(4) = 1 Then
Row("Active") = "False"
End If
Table1.Rows.Add(Row)
End While
Dim objDataView As New DataView(Table1)
DataGrid1.DataSource = objDataView
myConnection.Close()
how can i change the back color of rows in DataGrid when Active=True... and i need to change only that particular row's back color were Active=True...
if you have any idea how to do this please help me... and if you can provide an example, then it will be great help for me...
thanks in advance.