How to Format Rows in DataGridView In VB.NET

Respons: 0 comments

How to Format Rows in DataGridView In VB.NET

Here is small example to format the rows backColor , You need write the code in CellFormatting Event of datagridview.



  Private Sub TxtList_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles TxtList.CellFormatting  
     For i As Integer = 0 To TxtList.RowCount - 1  
       If TxtList.Item("Status", i).Value = "Pending" Then  
         TxtList.Rows(i).DefaultCellStyle.BackColor = Color.Gold  
       ElseIf TxtList.Item("Status", i).Value = "Approved" Then  
         TxtList.Rows(i).DefaultCellStyle.BackColor = Color.YellowGreen  
       ElseIf TxtList.Item("Status", i).Value = "Decline" Then  
         TxtList.Rows(i).DefaultCellStyle.BackColor = Color.OrangeRed  
       End If  
     Next  
   End Sub  

Here TxtList is the DataGridView Control.



No comments:

Post a Comment

Copyright © MS SQL MS-ACCESS

Sponsored By: GratisDesigned By: Habib Blog