Search code examples
vb.netcomponentone

How to high light rows in list control in vb.net


I'm using C1List control named lstPats in my vb.net form.lstPats have id,patname,patemail columns, i need to colour the rows in lstPats if patemail value is null

what I have done so far is

enabled fetchrowstyle property of lstPats

following is the code that i've written in lstPats_FetchRowStyle event

  For i As Integer = 0 To lstPats.ListCount - 1
         If lstPats.GetItemText(i, 2) <> "" Then /* checks the patemail is null or not*/
            e.CellStyle.ForeColor = Color.Green
         End If
     Next

The problem is all rows in the lstPats turns green, I need only the row(s) that contains null value in column patemail


Solution

  • You need to rewrite the code in FetchRowsStyle Event like below to highlight only some rows

     Dim val As String = Me.lstPats.Columns(2).CellText(e.Row).ToString
     If val <> "" Then
        e.CellStyle.BackColor = Color.Green
     End If