当前位置: 代码迷 >> VB Dotnet >> datagrid怎么定位到某一个单元格
  详细解决方案

datagrid怎么定位到某一个单元格

热度:162   发布时间:2016-04-25 02:01:05.0
datagrid如何定位到某一个单元格
以下是源代码,定位到某一列,然后根据某一列的数值范围定义字体颜色,现在增加一个条件,就是当某一行和某一列的数值范围在某一个范围,字体变色,请问如何修改下面的代码?


 Private Sub KuoTongDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles KuoTongDataGrid.ItemDataBound


    If e.Item.ItemType = ListItemType.Header Then
   Else
     Dim TM As Integer
    TM = CInt(e.Item.Cells(10).Text)

     If TM = 3 Then
      If CDbl(Val(Mid(e.Item.Cells(10).Text, 1, (InStr(e.Item.Cells(10).Text, "%") - 1)))) < CDbl("10") Then
         e.Item.Cells(10).ForeColor = Color.Red
   End If
End If

  If TM = 4 Then
  If CDbl(Val(Mid(e.Item.Cells(10).Text, 1, (InStr(e.Item.Cells(10).Text, "%") - 1)))) < CDbl("20") Then
     e.Item.Cells(10).ForeColor = Color.Red
      End If
     End If


------解决思路----------------------
        For Each r2 As DataGridViewRow In view1.Rows
            If r2.Cells(0).Value > r2.Cells(1).Value And r2.Cells(0).Value < r2.Cells(2).Value Then
                r2.DefaultCellStyle.ForeColor = Color.Red
            End If
        Next
  相关解决方案