您的位置:程序门 -> .net技术 -> vb.net



如何用指定的颜色显示datagridview中特定的行


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何用指定的颜色显示datagridview中特定的行
发表于:2007-01-18 09:27:14 楼主
如何用指定的颜色显示datagridview中特定的行。比如字段值为“可用”的行

if   me.datagridview1.columns(e.columnindex).name   =   "v_status "   then
                        '   检查该值是否符合条件。
                        if   instr(e.value,   "可用 ")   then
                                'e.cellstyle.forecolor   =   color.red
                                e.cellstyle.backcolor   =   color.lightblue
                        end   if
                end   if
这个方法只能改变单元格的颜色,如何才能改变整行的颜色
发表于:2007-01-18 09:32:081楼 得分:0
在datatable里直接改,哈哈
datatable       dt=new       datatable();      
    dt=dataset1.table[ "tablename "];      
    for(int       i=0;i <dt.rows.count;i++)      
    {      
                if(dt.rows[i][ "列名稱 "].tostring()== "條件 ")      
                    {      
    dt.rows[i][ "列名稱 "]= " <font       color=red> "+dt.rows[i][ "列名稱 "].tosting()+ " </font> ";      
                    }      
    }      
发表于:2007-01-18 09:38:382楼 得分:0
'   format   cell
        private   sub   dgvmessage_cellformatting(byval   sender   as   object,   byval   e   as   system.windows.forms.datagridviewcellformattingeventargs)   handles   dgvmessage.cellformatting
                if   e   isnot   nothing   then
                        dim   rowid   as   integer   =   e.rowindex
                        dim   colid   as   integer   =   e.columnindex

                        if   (rowid   > =   0   and   colid   > =   0)   andalso   not   me.dgvmessage.rows(rowid).isnewrow   then
                                try
                                        if   me.dgvmessage.columns(e.columnindex).name   =   "message_level "   then
                                                '   id   color   for   message   level
                                                dim   msglevel   as   integer   =   e.value

                                                select   case   msglevel
                                                        case   simpleloger.messagelevel.warnning
                                                                dim   cellbackcolor   as   system.drawing.color   =   color.yellow

                                                                for   each   cell   as   datagridviewcell   in   me.dgvmessage.rows(rowid).cells
                                                                        cell.style.backcolor   =   cellbackcolor
                                                                next
                                                        case   simpleloger.messagelevel.fault
                                                                dim   cellbackcolor   as   system.drawing.color   =   color.red

                                                                for   each   cell   as   datagridviewcell   in   me.dgvmessage.rows(rowid).cells
                                                                        cell.style.backcolor   =   cellbackcolor
                                                                next
                                                end   select
                                        end   if
                                catch   ex   as   exception
                                        debug.writeline(ex.message   &   vbtab   &   ex.stacktrace)
                                end   try
                        end   if
                end   if
        end   sub
发表于:2007-01-18 09:42:123楼 得分:0
绑定后遍历datagriditem,根据条件决定datagriditem.backcolor
发表于:2007-01-18 09:58:274楼 得分:0
datagrid1_itemdatabound事件中写以下代码
  dim   listtype   as   listitemtype
                listtype   =   e.item.itemtype
                if   (listtype   =   listitemtype.item)   or   (listtype   =   listitemtype.alternatingitem)   or   (listtype   =   listitemtype.edititem)   then
                        dim   str   as   string
                        str   =   e.item.cells(0).text
                        if   str   =   "我指定的值 "   then
                                e.item.backcolor   =   color.red
                        end   if
                end   if
发表于:2007-01-18 10:18:295楼 得分:0
datagrid1.rows(行号).defaultcellstyle.backcolor   =   color.green

vs2005+datagridview
发表于:2007-01-18 11:22:286楼 得分:0
收藏
发表于:2007-01-18 11:27:477楼 得分:0
大家好
发表于:2007-01-18 15:52:398楼 得分:0
根据条件决定datagriditem.backcolor


快速检索

最新资讯
热门点击