Hi Gemma,
"midgetgem" <
[email protected]> schreef in bericht
[...]
and that's about it really, it never breaks in my overridden paint
method.
Thanks for your help, and I look forward to your reply!
Gemma
I'll give you a small example, one that works as I explained. Maybe you can
use it to correct whatever you're doing wrong.
// -- form code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace GridTest
{
public partial class Form1 : Form
{
private DataTable gridData;
public Form1()
{
InitializeComponent( );
InitializeDS( );
InitializeGrid( );
FillGrid( );
}
private void FillGrid( )
{
for( int i = 0; i != 1000; ++i )
{
DataRow dr = gridData.NewRow( );
dr[ "Value" ] = i;
gridData.Rows.Add( dr );
}
}
private void InitializeDS( )
{
gridData = new DataTable( );
gridData.Columns.Add( new DataColumn( "Value", typeof( string ) ) );
ValueGrid.SetDataBinding( gridData, null );
}
private void InitializeGrid( )
{
DataGridColoredTextCol dgctc = new DataGridColoredTextCol( );
dgctc.Format = "";
dgctc.FormatInfo = null;
dgctc.HeaderText = "Value";
dgctc.MappingName = "Value";
dgctc.Width = 200;
dgctc.ReadOnly = true;
DataGridTableStyle dgts = new DataGridTableStyle( );
dgts.GridColumnStyles.AddRange ( new
System.Windows.Forms.DataGridColumnStyle[ ] { dgctc } );
ValueGrid.TableStyles.AddRange( new
System.Windows.Forms.DataGridTableStyle[ ] { dgts } );
}
}
}
// -- designer generated code
namespace GridTest
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.ValueGrid = new System.Windows.Forms.DataGrid( );
( (System.ComponentModel.ISupportInitialize) (
this.ValueGrid ) ).BeginInit( );
this.SuspendLayout( );
//
// ValueGrid
//
this.ValueGrid.DataMember = "";
this.ValueGrid.HeaderForeColor =
System.Drawing.SystemColors.ControlText;
this.ValueGrid.Location = new System.Drawing.Point( 12, 12 );
this.ValueGrid.Name = "ValueGrid";
this.ValueGrid.ReadOnly = true;
this.ValueGrid.Size = new System.Drawing.Size( 592, 443 );
this.ValueGrid.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 13F );
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size( 616, 467 );
this.Controls.Add( this.ValueGrid );
this.Name = "Form1";
this.Text = "Form1";
( (System.ComponentModel.ISupportInitialize) (
this.ValueGrid ) ).EndInit( );
this.ResumeLayout( false );
}
#endregion
private System.Windows.Forms.DataGrid ValueGrid;
}
}
// -- The DataGridColoredTextCol class
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace GridTest
{
public class DataGridColoredTextCol : DataGridTextBoxColumn
{
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 )
{
if( ( rowNum + 1 ) % 5 == 0 )
backBrush = System.Drawing.Brushes.Red;
base.Paint( g, bounds, source, rowNum, backBrush, foreBrush,
alignToRight );
}
}
}
Kind regards,