Click here to Skip to main content
11,582,800 members (70,737 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
i have one form where columns are name,type,size,date.

the data displays in gridview.

i want all the rows of date column to get in red colour.

how to change that in properties

Will be obliged if anyone can help me.

thanks in advance
Posted 7-Jul-13 23:25pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

for (int i = 0; i < gridview1.Rows.Count; i++)
            {
                gridview1.Rows[i].Cells[gridview1.Columns.Count - 1].BackColor = Color.Red;
            }


Accept as answer and vote if help.
  Permalink  
Comments
sudeshna from bangkok at 8-Jul-13 6:04am
   
thanks for the reply but where should i write this code?

under button_click?

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=record;user=sa;password=gariahat")
Dim da As New SqlDataAdapter
Dim cmd As New SqlCommand
Dim ds As New DataSet
Dim tb2 As DataTable
Dim i As Integer
Try
cmd.Connection = cn
cn.Open()
da = New SqlDataAdapter("select * from facsort", cn)
tb2 = New DataTable
da.Fill(tb2)
FacsortDataGridView.DataSource = tb2


Catch ex As Exception
MsgBox(ex.Message)
End Try
jaideepsinh at 8-Jul-13 6:10am
   
After grid bind code:
FacsortDataGridView.DataSource = tb2
sudeshna from bangkok at 8-Jul-13 6:34am
   
can you write the code in vb.net 2008. i am using this version. so showing error in 1st for loop statement
jaideepsinh at 8-Jul-13 7:30am
   
For i As Integer = 0 To Me.DataGridView1.Rows.Count - 1
DataGridView1.Rows[i].Cells[DataGridView1.Columns.Count - 1].BackColor = Color.Red;
Next
sudeshna from bangkok at 8-Jul-13 22:38pm
   
DataGridView1.Rows[i].Cells[DataGridView1.Columns.Count - 1].BackColor = Color.Red;

this full line is showing error.

cells is not a member of integer
bracketed identifier is missing ']]
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

.gridcss
{
background:Red;
color:White;
}


Protected Sub gvdata_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(3).CssClass = "gridcss"
 
End If
End Sub
 

  Permalink  
v4
Comments
sudeshna from bangkok at 8-Jul-13 6:32am
   
where to use drv variable.its showing error on drv.
Nirav Prabtani at 8-Jul-13 6:38am
   
try without declaring drv ... :)
sudeshna from bangkok at 8-Jul-13 6:49am
   
your code is selecting my 3rd row and making it full red.

but i want only the last column all data(rows) to be red.that is only the textcolor.
Nirav Prabtani at 8-Jul-13 6:56am
   
Try my updated solution.
sudeshna from bangkok at 8-Jul-13 7:03am
   
no property is there like rowdatabound in the declarations
Nirav Prabtani at 8-Jul-13 7:06am
   
try this link....:)

http://www.vbforums.com/showthread.php?465358-RESOLVED-Change-DataGridView-cell-color-based-on-other-columns
sudeshna from bangkok at 8-Jul-13 22:51pm
   
thanks.solved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 305
1 Sergey Alexandrovich Kryukov 220
2 Andy Lanng 114
3 Stefan_Lang 110
4 virusstorm 109
0 OriginalGriff 1,358
1 Sergey Alexandrovich Kryukov 970
2 Abhinav S 671
3 F-ES Sitecore 505
4 Suvendu Shekhar Giri 448


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 8 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100