473,511 Members | 14,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

change row color of DataGrid in VB.Net (Windows application)

115 New Member
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.
Expand|Select|Wrap|Line Numbers
  1.  Dim Table1 As DataTable = New DataTable("Orders")
  2.         Dim Row As DataRow
  3.  
  4.         Dim EmpName As DataColumn = New DataColumn("EmpName")
  5.        Table1.Columns.Add(EmpName)
  6.  
  7.         Dim EmployeeID As DataColumn = New DataColumn("EmpID")
  8.         EmployeeID.DataType = System.Type.GetType("System.Int32")
  9.         Table1.Columns.Add(EmployeeID)
  10.  
  11.         Dim CardNo As DataColumn = New DataColumn("CardNo")
  12.         CardNo.DataType = System.Type.GetType("System.Int32")
  13.         Table1.Columns.Add(CardNo)
  14.  
  15.         Dim Active As DataColumn = New DataColumn("Active")
  16.         Table1.Columns.Add(Active)
  17.  
  18.         Dim i As Integer = 0
  19.  
  20.         Dim strSQL As String = "Select LastName, FirstName, EmpID, CardNo, Active from Employees order by LastName asc"
  21.         myConnection.Open()
  22.         Dim myCommand As New OleDbCommand(strSQL, myConnection)
  23.         Dim myReader As OleDbDataReader = myCommand.ExecuteReader
  24.  
  25.        While myReader.Read
  26.             Row = Table1.NewRow()
  27.             Row("EmpName") = myReader(0) & "," & myReader(1)
  28.             Row("EmpID") = myReader(2)
  29.             Row("Card No") = myReader(3)
  30.             If myReader(4) = 0 Then
  31.                 Row("Active") = "True"
  32.             ElseIf myReader(4) = 1 Then
  33.                 Row("Active") = "False"
  34.             End If
  35.             Table1.Rows.Add(Row)
  36.          End While
  37.  
  38.         Dim objDataView As New DataView(Table1)
  39.         DataGrid1.DataSource = objDataView
  40.         myConnection.Close()
  41.  
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.
Oct 12 '07 #1
2 3826
kenobewan
4,871 Recognized Expert Specialist
I think there was a recent similar problem that used dhtml, try searching the site.
Oct 13 '07 #2
remya1000
115 New Member
while searching i found out a link. and this is that link i got...

http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q745q

here its using DataSet and it will check each Columns and if first alphabet in column is greater than "F" then it will change the colour of that column. but not the entire row.

in my program i need to change the colour of row according to the Field name Active. but i don't need to display the field Active. only the remaining fields i need to display and active is used to check if Active is True, then Row colour should be Pink and if Active is False then row colour is white.

and i tried using DataTable instead of DataSet in that example but wont change the colour at all... but if we use DataSet then it will change colour.

i'm new to programming... so you have any idea how to do this please let me know... and if you can provide any help then it will be great helpfull for me.

thanks in advance.
Oct 15 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3239
by: Tamlin | last post by:
Hi all, I'm getting a bug with the datagrid object. I've created one from scratch, bound it to a dataview with 2 int32 columns and formatted the output as currency. I've found that when you...
0
1515
by: metamedia | last post by:
How do I get a datagrid to register a data change from a custom control cell (combobox) I've got a Windows Application with a Windows Form Datagrid that has a custom combobox column. When the user...
3
10390
by: Ajay Krishnan Thampi | last post by:
I have a slight problem implementing 'drag and drop' from a datagrid to a tree-view. I have pasted my code below. Someone please advice me on what to do...pretty blur right now. ==code== ...
2
2338
by: Raj | last post by:
Hi, When we are sorting the DataGrid Boolean column the grid is becoming redcross. I have my own PPMIPDataGridBoolColumn class inherited from System.Windows.Forms.DataGridBoolColumn. In this...
3
5020
by: Ryan Liu | last post by:
Hi there, I got a NullReferenceException when delete last row in a datagrid. I had hard time to solve since it does not occur in my own code. I put a datagrid in my inherited user control,...
0
1058
by: Inigo Jimenez | last post by:
I have an ASP .net web application installed in a Windows 2003 server. This web application has a webform that has a Datagrid with smartnavigation enabled. In this webpage I have a button that...
8
1916
by: Inigo Jimenez | last post by:
I have an ASP .net web application installed in a Windows 2003 server. This web application has a webform that has a Datagrid. This Datagrid is filled with the data of a SQL table. I have a...
7
7735
by: Wayne Wengert | last post by:
I am using VB with a Windows NET application. I have a datagrid in which the user can add rows using the "*" row. I want to detect whenever the user has added a row. I found the following code at...
5
4230
by: HS1 | last post by:
Hello I have a datagrid to show data for a database table using "seclect * from tablename" The datagrid works OK. However, I want to change the name of the fields in the database to other...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7148
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.