找回密码
 注册
搜索
热搜: java php web
查看: 186|回复: 2

GridView 隔行显色

[复制链接]
发表于 2009-11-21 11:57:52 | 显示全部楼层 |阅读模式
private   void   dataGridView1_DataBindingComplete(object   sender,   DataGridViewBindingCompleteEventArgs   e)   
{   
           if (this.dataGridView1.Rows.Count != 0)   
           {   
              for (int i = 0; i < this.dataGridView1.Rows.Count; )   
              {   
                  this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;   
                   i += 2;   
               }   
           }   
}

相关帖子

 楼主| 发表于 2009-11-21 11:59:33 | 显示全部楼层
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.CodeDom.Compiler;
using System.Reflection;
using Microsoft.JScript;
namespace ClassLibrary1
{    public class Evaluator
    {
        private static Type _evaluatorType = null;
        private static readonly string _jscriptSource =
            @"package Evaluator
                {
                    class Evaluator
                    {
                        public function Eval(expr : String) : String
                        {
                             
                                  return eval(expr);
                             
                        }
                    }
                }";

        static Evaluator()
        {
            ICodeCompiler compiler;
            compiler = new JScriptCodeProvider().CreateCompiler();

            CompilerParameters parameters;
            parameters = new CompilerParameters();
            parameters.GenerateInMemory = true;

            CompilerResults results;
            results = compiler.CompileAssemblyFromSource(parameters,
                                 _jscriptSource);

            Assembly assembly = results.CompiledAssembly;
            _evaluatorType = assembly.GetType("Evaluator.Evaluator");

        }

        // ...
        public static bool EvalToBoolean(string statement)
        {
            string s = EvalToString(statement);
            return bool.Parse(s);
        }

        public static string EvalToString(string statement)
        {
            object o = EvalToObject(statement);
            return o.ToString();
        }

        public static object EvalToObject(string statement)
        {
            object evaluator = Activator.CreateInstance(_evaluatorType);
            return _evaluatorType.InvokeMember("Eval",
                    BindingFlags.InvokeMethod, null, evaluator, new object[]
                                                          { statement } );               
        }
        public static void Main(string[] arge)
        {
            EvalToBoolean("1 == 1");
            Console.WriteLine(EvalToBoolean("1 == 1"));
         
            ////
           // Lot lot = new Lot("Lot1");
           // Console.WriteLine(lot.ID);
           //      Console.WriteLine(lot.AMOUNT );
           //  Console.WriteLine(lot.getTotal() );
            
            //dynamic
            string script = @"   var yield =100;
                                 if (Lot.getCurrentYield() <90 ) {  
                                     yield  = 90;
                                  }
                                  return yield;
                                   ";
             Type visualStudioType = Type.GetType("ClassLibrary1.Lot");
            Object[] lotid = {"Lot15"};
            dynamic dte = Activator.CreateInstance(visualStudioType, lotid);
            Console.WriteLine("========================================");
            Console.WriteLine(dte.ID);
            Console.WriteLine(dte.AMOUNT);
            Console.WriteLine(dte.getCurrentYield());
            //
            Type visualStudioType2 = Type.GetType("ClassLibrary1.Eqp");
            Object[] eqpid = { "EP1" };
            dynamic dte2 = Activator.CreateInstance(visualStudioType2, eqpid);
            Console.WriteLine("========================================");
            Console.WriteLine(dte2.ID);
            Console.WriteLine(dte2.getCapacity());
            Console.Read();
        }
    }
}
回复

使用道具 举报

发表于 2009-12-15 11:56:24 | 显示全部楼层
太复杂了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|软晨网(RuanChen.com)

GMT+8, 2024-9-20 13:55

Powered by Discuz! X3.5

Copyright © 2001-2023 Tencent Cloud.

快速回复 返回顶部 返回列表