Search
Active

1
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 507351
Opened: 11/1/2009 4:43:36 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
 WindowsFormアプリーケーションで、DataGridViewの新規行からDataSourceのレコードを移動すると表題のエラーが発生します。
 DataGridViewにCurrencyManagerによるカーソル移動をサポートしたBindingSourceなどのコンポーネントをDataSourceに指定します。BindingSourceのMoveFirstメソッドで新規行から既存行に移動し、再び新規行に移動するとエラーが発生します。新規行から既存行に移動するのに矢印キーを使った場合は該当の現象は起こりません。また、MoveFirstを呼び出す前にFormのValidateメソッドを呼ぶとこのエラーは起こりません。
 私はValidateメソッドを呼ばなくてもこのようなエラーが起こらないことを希望します。
 現状ですとBindingSourceを操作するプログラムは、BindingSourceがDataGridViewにバインディングされているかどうかを意識しなければならず、結合度が高くなってしまうからです。

 NetFrameworkのソースをステッピングすると、新規行から既存行に移動するときに、矢印キーを使った場合にはCancelEdit、CancelNewが発生しています。それに対してMoveFirstメソッドを呼び出した場合はEndEdit、EndNewが発生し、次に下矢印キーで移動したときにCancelEdit、CancelNewが発生します。このようにDataGridViewの内部状態が矛盾します。
 このようなことが起こらないようにするためには、CurrencyManagerやBindingSourceを拡張してPosition変更前に発生するイベント"PositionChanging"や"CurrentChanging"を新たに設け、DataGridViewはこのイベントを捕捉してCancelEdit、CancelNewを発生させるのが良いと思います。
Details (expand)
製品言語
日本語
製品名
Visual Studio 2008 SP1
オペレーティング システム
Windows XP Professional
オペレーティング システム言語
日本語
再現手順
1)Windows Formを作成する
2)DataGridView、BindingSource、ToolStripを配置する
3)ToolStrip上にボタンを追加する
4)Formのコードを以下の通りとする
 (FormのLoadイベント、ボタンのClickイベントを捕捉すること)

using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace DataGridViewBug
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

public class CodeAndName
{
public int? Code { get; set; }
public string Name { get; set; }
}

private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.AutoGenerateColumns = true;
bindingSource1.DataSource = new BindingList<CodeAndName>();
}

private void toolStripButton1_Click(object sender, EventArgs e)
{
//Validate();
bindingSource1.MoveFirst();
}
}
}

5)ビルド後実行する
6)1行データを追加する
7)2行目に移動する
8)ToolStrip上のボタンを押して1行目に移動する
9)下矢印で2行目に移動する
実際の結果
表題のエラーが発生する
期待した結果
エラーが発生しないこと
TAP コード (お持ちの場合のみ)
 
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 11/4/2009 at 12:29 AM
この度は、フィードバックをお送りいただき、誠にありがとうございます。 現在、お送りいただきました報告内容に基づき問題を調査中ですので、しばらくお待ちください。 よろしくお願いいたします。

[Problem Description]
When you move focus from a new DataSource row to an existing one in DataGridView on a Windows Form Application program, the captioned error occurs. You set to DataSource of DataGridView a component like BindingSource that supports cursor move by CurrencyManager. When you use the MoveFirst method of BindingSource to move from a new row to an existing one and then go back to the new one, the error occurs. When you use an ARROW key to move from a new row to an existing one, the symptom does not occur. No error occurs either when you call the Validate method of the form before calling MoveFirst.

I hope the error does not occur even if the Validate method is not called. This is because, at present, a program that handles BindingSource needs to consider if BindingSource is bound to DataGridView, which results in high coupling.

When you step in .NET Framework source code and use an ARROW key to move from a new row to an existing one, CancelEdit and CancelNew occur. On the other hand, when the MoveFirst method is called, EndEdit and EndNew occur. When you use the DOWN ARROW key to move next, CancelEdit and CancelNew occur. Like this, inconsistency is generated in the status inside DataGridView.

To prevent this, CurrencyManager or BindingSource should be extended to add a new event like "PositionChanging" or "CurrentChanging" that occurs before position change, and DataGridView should catch this event to raise CancelEdit and CancelNew.

[Repro Steps]
1) Create a Windows Form Application program.
2) Place DataGridView, BindingSource, and ToolStrip.
3) Add a button on the ToolStrip.
4) Write source code on the form as below. (The Load event of the form and the Click event of the button should be caught.)

using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace DataGridViewBug
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

public class CodeAndName
{
public int? Code { get; set; }
public string Name { get; set; }
}

private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.AutoGenerateColumns = true;
bindingSource1.DataSource = new BindingList<CodeAndName>();
}

private void toolStripButton1_Click(object sender, EventArgs e)
{
//Validate();
bindingSource1.MoveFirst();
}
}
}

5) Build and run.
6) Add data in the first row.
7) Move to the second row.
8) Click the button on the ToolStrip and move to the first row.
9) Use the DOWN ARROW key to move to the second row.

[Actual Results]
The captioned error occurs.

[Expected Results]
No error occurs.
Posted by Microsoft on 11/11/2009 at 4:56 AM
Thanks for your feedback. We are routing this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team
Posted by Microsoft on 11/11/2009 at 6:00 PM
Thanks for your feedback on the .NET Framework!

We are able to reproduce the bug that you reported and plan to conduct in-depth investigation. Since team here is focusing on stablizing and finalizing VS2010 RC bits, we'll keep you updated once progress is made on this problem.

Regards,
UIFx Team
Posted by Microsoft on 11/11/2009 at 6:27 PM
(こちらは、[投稿者: Microsoft、投稿日時: 2009/11/11 4:56] の和訳です。)

フィードバックをお寄せいただき、ありがとうございます。 こちらのバグに関しましては、該当する機能を専門で担当している製品チームに報告させていただきます。 今後は、同チームが問題を再調査し、次期リリース版での修正について判断する予定です。 よろしくお願いいたします。

Visual Studio 製品チーム
Posted by Microsoft on 11/11/2009 at 6:37 PM
(こちらは、[投稿者: Microsoft、投稿日時: 2009/11/11 18:00] の和訳です。)

.NET Framework に関するフィードバックをお寄せいただき、ありがとうございます!

私たちの方で 三輪の牛 さんからご報告いただきましたバグを再現することができましたので、掘り下げた調査を実施したいと考えております。 担当チームは現在、Visual Studio 2010 RC 版の安定性確認および最終仕上げに集中しておりますので、こちらの問題に関しましては、進捗があり次第お知らせさせていただきます。 よろしくお願いいたします。

UIFx チーム