示例#1
0
 private void SetCellFormat(object sender, DataGridFormatCellEventArgs e)
 {
     try
     {
         bool discontinued = (bool)((e.Column != 0) ? this.dataGrid1[e.Row, 0] : e.CurrentCellValue);
         if (e.Column > 0 && (bool)(this.dataGrid1[e.Row, 0]))               //discontinued)
         {
             //				e.BackBrush = this.disabledBackBrush;
             e.ForeBrush = this.disabledTextBrush;
         }
         else if (e.Column > 0 && e.Row == this.dataGrid1.CurrentRowIndex)               //discontinued)
         {
             e.BackBrush = this.currentRowBackBrush;
             e.TextFont  = this.currentRowFont;
         }
         if (discontinued)
         {
             if (decimal.Parse(this.dataGrid1[e.Row, 9].ToString()) == 0)
             {
                 e.BackBrush = new SolidBrush(Color.LightSkyBlue);
             }
         }
     }
     catch {}
 }
示例#2
0
 private void SetCellFormat(object sender, DataGridFormatCellEventArgs e)
 {
     try
     {
         bool discontinued = (bool)((e.Column != 0) ? this.dataGrid1[e.Row, 0] : e.CurrentCellValue);
         if (e.Column > 0 && (bool)(this.dataGrid1[e.Row, 0]))               //discontinued)
         {
             e.ForeBrush = this.disabledTextBrush;
         }
         else if (e.Column > 0 && e.Row == this.dataGrid1.CurrentRowIndex)               //discontinued)
         {
             e.BackBrush = this.currentRowBackBrush;
             e.TextFont  = this.currentRowFont;
         }
     }
     catch {}
 }
示例#3
0
        //overridden to fire BoolChange event and Formatting event
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
        {
            int colNum = this.DataGridTableStyle.GridColumnStyles.IndexOf(this);

            //used to handle the boolchanging
            ManageBoolValueChanging(rowNum, colNum);

            //fire formatting event
            DataGridFormatCellEventArgs e = null;
            bool callBaseClass            = true;

            if (SetCellFormat != null)
            {
                e = new DataGridFormatCellEventArgs(rowNum, colNum, this.GetColumnValueAtRow(source, rowNum));
                SetCellFormat(this, e);
                if (e.BackBrush != null)
                {
                    backBrush = e.BackBrush;
                }
                callBaseClass = e.UseBaseClassDrawing;
            }
            if (callBaseClass)
            {
                base.Paint(g, bounds, source, rowNum, backBrush, new SolidBrush(Color.Red), alignToRight);
            }

            //clean up
            if (e != null)
            {
                if (e.BackBrushDispose)
                {
                    e.BackBrush.Dispose();
                }
                if (e.ForeBrushDispose)
                {
                    e.ForeBrush.Dispose();
                }
                if (e.TextFontDispose)
                {
                    e.TextFont.Dispose();
                }
            }
        }
示例#4
0
 private void SetCellFormat2(object sender, DataGridFormatCellEventArgs e)
 {
     try
     {
         bool discontinued = (bool)((e.Column != 0) ? this.dataGrid2[e.Row, 0] : e.CurrentCellValue);
         if (e.Column > 0 && (bool)(this.dataGrid2[e.Row, 0]))
         {
             e.ForeBrush = this.disabledTextBrush;
         }
         else if (e.Column > 0 && this.dataGrid2[e.Row, 4].ToString() == "0")
         {
             e.ForeBrush = this.RowBackBrushVP;
         }
         else if (e.Column > 0 && e.Row == this.dataGrid2.CurrentRowIndex)
         {
             e.BackBrush = this.currentRowBackBrush;
             e.TextFont  = this.currentRowFont2;
         }
     }
     catch {}
 }
示例#5
0
        //used to fire an event to retrieve formatting info
        //and then draw the cell with this formatting info
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
        {
            DataGridFormatCellEventArgs e = null;

            bool callBaseClass = true;

            //fire the formatting event
            if (SetCellFormat != null)
            {
                int col = this.DataGridTableStyle.GridColumnStyles.IndexOf(this);
                e = new DataGridFormatCellEventArgs(rowNum, col, this.GetColumnValueAtRow(source, rowNum));
                SetCellFormat(this, e);

                if (e.BackBrush != null)
                {
                    backBrush = e.BackBrush;
                }

                //if these properties set, then must call drawstring
                if (e.ForeBrush != null || e.TextFont != null)
                {
                    if (e.ForeBrush == null)
                    {
                        e.ForeBrush = foreBrush;
                    }
                    if (e.TextFont == null)
                    {
                        e.TextFont = this.DataGridTableStyle.DataGrid.Font;
                    }
                    g.FillRectangle(backBrush, bounds);
                    Region    saveRegion = g.Clip;
                    Rectangle rect       = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height);
                    using (Region newRegion = new Region(rect))
                    {
                        g.Clip = newRegion;
                        int charWidth = (int)Math.Ceiling(g.MeasureString("c", e.TextFont, 20, StringFormat.GenericTypographic).Width);

                        string s        = this.GetColumnValueAtRow(source, rowNum).ToString();
                        int    maxChars = Math.Min(s.Length, (bounds.Width / charWidth));

                        try
                        {
                            g.DrawString(s.Substring(0, maxChars), e.TextFont, e.ForeBrush, bounds.X, bounds.Y + 2);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message.ToString());
                        }                         //empty catch
                        finally
                        {
                            g.Clip = saveRegion;
                        }
                    }
                    callBaseClass = false;
                }

                if (!e.UseBaseClassDrawing)
                {
                    callBaseClass = false;
                }
            }
            if (callBaseClass)
            {
                base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
            }

            //clean up
            if (e != null)
            {
                if (e.BackBrushDispose)
                {
                    e.BackBrush.Dispose();
                }
                if (e.ForeBrushDispose)
                {
                    e.ForeBrush.Dispose();
                }
                if (e.TextFontDispose)
                {
                    e.TextFont.Dispose();
                }
            }
        }