当前位置: 代码迷 >> VB Dotnet >> Vb.Net—DateGrid,该如何解决
  详细解决方案

Vb.Net—DateGrid,该如何解决

热度:449   发布时间:2016-04-25 02:25:29.0
Vb.Net—DateGrid
关于 VB.Net    DateGrid问题,我在绑定DateGrid时候,数据是这样的

   ID      type    start    end    RangeNo
  1001      1        0       1       123
  1001      1        1       2       456
  1001      1        2       5       789
  1001      1        5       max     012
 
 1002      2        0       1       123
  1002      2        1       2       456
  1002      2        2       5       789
  1002      2        5       max     012

类似这样的数据, 我现在想就是 绑定的时候判断 ID 跟Type 一样的 设置成一个颜色,当ID或者Type不一样的时候就换成另一种颜色! DateGrid 里面有什么方法可以实现嘛
 
------解决方案--------------------
那你取出数据里,
ItemDataBound
   e.Item.Cells(0).BackColor = System.Drawing.Color.Blue;
------解决方案--------------------
类似的
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            foreach (DataGridItem item in DataGrid1.Items)
            {
                   item.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='#b7c4e2'");
                item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor");                
            }
        }
------解决方案--------------------
这个只是说mouse移动到单元格时这个单元格变色

------解决方案--------------------
 Private Sub DataGridView1_CellFormatting(sender As Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
        If Me.DataGridView1.Columns(e.ColumnIndex).Name = "Id" Then
            If e.Value IsNot Nothing Then
                If e.Value < 3 Then
                    Me.DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Yellow
                Else
                    Me.DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Blue

                End If
            End If
        End If
    End Sub

------解决方案--------------------
每4行,可用If e.Value mod 4=0 Then 这样,你看可行不?