here is some sample code.
i bind textbox1 to a column which has the text "bjarne"
when i type "arne" in the textbox its supposed to be an error.
what happens when i type "arne" is that
row.setcolumnerror(inedx,"somerrror"); is called.
the problem is i guess that before this method is done .net rollbacks the
change so the textbox displays "bjarne" and that triggers the
textbox.ontextchanged that does the row.setcolumnerror(index,null);
so the columnerror is removed before
row.setcolumnerror(inedx,"somerrror");
method is done.
so i guess if i can make .net leave the "arne" in the textbox instead of
rollingback to "bjarne" it will probably work
-Geir
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication2
{
/// <summary>
/// Summary description for Form3.
/// </summary>
public class Form3 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private Infragistics.Win.UltraWinGrid.UltraGrid ultraGrid1;
private DataSet ds = new DataSet();
public Form3()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(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.textBox1 = new System.Windows.Forms.TextBox();
this.ultraGrid1 = new Infragistics.Win.UltraWinGrid.UltraGrid();
((System.ComponentModel.ISupportInitialize)(this.ultraGrid1)).BeginInit();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.CausesValidation = false;
this.textBox1.Location = new System.Drawing.Point(88, 88);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(192, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
this.textBox1.TextChanged += new
System.EventHandler(this.textBox1_TextChanged);
//
// ultraGrid1
//
this.ultraGrid1.Location = new System.Drawing.Point(48, 160);
this.ultraGrid1.Name = "ultraGrid1";
this.ultraGrid1.Size = new System.Drawing.Size(440, 208);
this.ultraGrid1.TabIndex = 1;
this.ultraGrid1.Text = "ultraGrid1";
//
// Form3
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(624, 413);
this.Controls.Add(this.ultraGrid1);
this.Controls.Add(this.textBox1);
this.Name = "Form3";
this.Text = "Form3";
this.Load += new System.EventHandler(this.Form3_Load);
((System.ComponentModel.ISupportInitialize)(this.ultraGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void textBox1_TextChanged(object sender, System.EventArgs e) {
if (textBox1.Text == "arne") {
CurrencyManager cm =
(CurrencyManager)textBox1.BindingContext[ds,"test"];
DataRow row = ds.Tables["test"].Rows[cm.Position];
int index = ds.Tables["test"].Columns.IndexOf("name2");
textBox1.BackColor = Color.Red;
textBox1.TextChanged -= new
System.EventHandler(this.textBox1_TextChanged);
row.SetColumnError(index,"somerror");
textBox1.TextChanged += new
System.EventHandler(this.textBox1_TextChanged);
} else {
CurrencyManager cm =
(CurrencyManager)textBox1.BindingContext[ds,"test"];
DataRow row = ds.Tables["test"].Rows[cm.Position];
int index = ds.Tables["test"].Columns.IndexOf("name2");
textBox1.BackColor = Color.White;
if (!row.GetColumnError(index).Equals(""))
row.SetColumnError(index,null);
}
}
private void Form3_Load(object sender, System.EventArgs e) {
DataTable t = ds.Tables.Add("test");
t.Columns.Add("id",typeof(decimal));
t.Columns.Add("name",typeof(string));
t.Columns.Add("name2",typeof(string));
DataRow r1 = t.NewRow();
r1[0] = 1;
r1[1] = "geir";
r1[2] = "bjarne";
t.Rows.Add(r1);
textBox1.DataBindings.Add("Text", ds, "test.name2");
ultraGrid1.SetDataBinding(ds,"test");
}
}
}