VB.net中根据内容改变datagridview单元格颜色
来源:优易学  2011-12-10 20:18:29   【优易学:中国教育考试门户网】   资料下载   IT书店
  1PrivateSubcustomerDataGridView_CellFormatting(ByValsenderAsObject,ByValeAsDataGridViewCellFormattingEventArgs)HandlescustomerDataGridView.CellFormatting
  2 
  3  ’Ifthecolumnbeingformattedisthecolumnnamed’Status’..
  4  IfMe.customerDataGridView.Columns(e.ColumnIndex).Name="Status"Then
  5    Ife.ValueIsNotNothingThen
  6      ’Ifthevalueofthecellis"Inactive"ANDthisform’sinactiveCustomersCheckBoxcontrolischecked..
  7      Ife.Value.ToString="Inactive"AndMe.inactiveCustomersCheckBox.CheckedThen
  8        ’SettheBackColorofthecelltoyellow.
  9        e.CellStyle.BackColor=Color.Yellow
  10      EndIf
  11    EndIf
  12  EndIf
  13
  14  ’Ifthecolumnbeingformattedisthecolumnnamed’LastOrderDate’..
  15  IfMe.customerDataGridView.Columns(e.ColumnIndex).Name="LastOrderDate"Then
  16    Ife.ValueIsNotNothingThen
  17      ’IfLastOrderDatewasmorethan30daysagoANDthisform’sordersOverdueCheckBoxcontrolischecked..
  18      IfDate.Now.Subtract(CType(e.Value,Date)).Days>30AndMe.orderOverdueCheckBox.CheckedThen
  19        ’SettheBackColorofthecelltoyellow-green.
  20        e.CellStyle.BackColor=Color.YellowGreen
  21      EndIf
  22    EndIf
  23  EndIf
  24EndSub

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训