表示されている動作は実際には絵の問題によるもので、エラーアイコンが表示されていないためではありません。何が起こっていることは、あなたがそれ故にセルのエラーテキストアイコンが表示されますが、編集モードでのセルのテキストボックスをアイコンの上に塗装され、ユーザーに表示されるアイコンなしを設定した場合ということです!
あなたはこれを固定するための2つの選択肢がある - 1は、単にので、代わりの行のエラーテキストを使用することです。他のオプションは、セルを変更することです
this.datagridviewX.Rows[e.RowIndex].ErrorText = "Errortext";
e.Cancel = true;
:
this.datagridviewX.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "Errortext";
e.Cancel = true;
あなたが持っているのセルのパディング(編集コントロールの移動)とアイコンのペイント。
実際には、この問題を解決するためにこのテクニックが見つかりましたhereと再現以下のコードを(C#ではVB.Netではなく)使用します。アイコンが表示されるようになりますないアイコンがあまりにも移動した以外の編集コントロールは、移動した
void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (string.IsNullOrEmpty(e.FormattedValue.ToString()))
{
DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
cell.ErrorText =
"Company Name must not be empty";
if (cell.Tag == null)
{
cell.Tag = cell.Style.Padding;
cell.Style.Padding = new Padding(0, 0, 18, 0);
}
e.Cancel = true;
}
else
{
dataGridView1.Rows[e.RowIndex].ErrorText = string.Empty;
}
}
:
まず、あなたは、セルのパディングを変更するには、いくつかのコードを追加し、イベントを検証し、あなたのセルを持っています!それで、新しいアイコンをペイントする必要もあります。
void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (dataGridView1.IsCurrentCellDirty)
{
if (!string.IsNullOrEmpty(e.ErrorText))
{
GraphicsContainer container = e.Graphics.BeginContainer();
e.Graphics.TranslateTransform(18,0);
e.Paint(this.ClientRectangle, DataGridViewPaintParts.ErrorIcon);
e.Graphics.EndContainer(container);
e.Handled = true;
}
}
}
あなたはセルで編集終了時に、あなたはパディングをリセットする必要があります。
void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (!string.IsNullOrEmpty(dataGridView1[e.ColumnIndex, e.RowIndex].ErrorText))
{
DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
cell.ErrorText = string.Empty;
cell.Style.Padding = (Padding)cell.Tag;
cell.Tag = null;
}
}
私は、これは新しい塗装、アイコン、マウスの上に設定する怠ったポスト - ここではいくつかあります私は後で分を取得する場合、私はそれを片付けるだろう - 私はそれを得るために時間が本当に働いていない、ということに対処ラフコードはそうだろうと思っ修正若干fudgesがあります。
私は= DataGridView.ShowCellToolTipsをtrueに設定し、我々は現在、編集エラーを持っている場合は追跡するブールinErrorをご紹介します。私は、MouseHoverイベントを処理する:
void dataGridView1_MouseHover(object sender, EventArgs e)
{
if (inError)
{
Point pos = this.PointToClient(Cursor.Position);
if (r.Contains(pos.X - 20, pos.Y - 5))
{
t.Show("There was an error", dataGridView1.EditingControl, 3000);
}
}
}
そのコードにおけるTは、フォームレベルのツールヒントコントロールであり、そしてrは矩形です。
私は、セルの塗装ハンドラに以下のようにrを移入
:
void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (dataGridView1.IsCurrentCellDirty)
{
if (!string.IsNullOrEmpty(e.ErrorText))
{
GraphicsContainer container = e.Graphics.BeginContainer();
r = dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
e.Graphics.TranslateTransform(18, 0);
e.Paint(this.ClientRectangle, DataGridViewPaintParts.ErrorIcon);
e.Graphics.EndContainer(container);
e.Handled = true;
}
}
}
私は位置ポイントにマイナス20、マイナス約5満足していない - それは私が持っていた場合、私はアップ修正したいものです少し時間がかかります。
私が私の答えで言うように、あなたが何を記述しているかは、すぐに使えるものではないので、珍しいことをしなければならない。いくつかのコードを提供できますか? –