- 題名: Bindinsourceのカレント行とDatagridviewの選択行について
- 日時: 2009/02/02 20:15:42
- ID: 23886
- この記事の返信元:
- (なし)
- この記事への返信:
- [23896] Re[1]: Bindinsourceのカレント行とDatagridviewの選択行について2009/02/03 18:53:57
- ツリーを表示
とりあえずですが・・・
グリッド内をクリックした後の、「キャンセル」する(選択行を戻す)処理について
DataGridViewをオーバーライドして、
SetCurrentCellAddressCore
の動きを追っていきました。
ところ・・
@セルをクリック
ASetCurrentCellAddressCoreが呼出される
BSetCurrentCellAddressCore内にて、BindingSourceのCurrentを変更
CDataGridViewのいろいろなイベントが走る
DSetCurrentCellAddressCoreの処理が終わる
EDataGridView.SelectionChangedイベントが送信される
まで分かりました。
以下が”セルをクリックした”時の対応分です。
Imports System.Windows.Forms
Public Class BaseDataGridView
Private _doCancel As Boolean = False
Private _Position As New Point(-99, -99)
Protected Overrides Function SetCurrentCellAddressCore( _
ByVal columnIndex As Integer, _
ByVal rowIndex As Integer, _
ByVal setAnchorCellAddress As Boolean, _
ByVal validateCurrentCell As Boolean, _
ByVal throughMouseClick As Boolean _
) As Boolean
If CurrentCell IsNot Nothing Then _Position = New Point(Me.CurrentCell.ColumnIndex, Me.CurrentCell.RowIndex)
Return MyBase.SetCurrentCellAddressCore(columnIndex, rowIndex, setAnchorCellAddress, validateCurrentCell, throughMouseClick)
End Function
Public Sub doCancel()
_doCancel = True
End Sub
Private Sub DataGridView_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.SelectionChanged
If Me.CurrentCell Is Nothing Then Exit Sub
If _doCancel Then
_doCancel = False
Me.CurrentCell = Me(_Position.X, _Position.Y)
End If
End Sub
End Class
分類:[.NET]
2009/02/03(Tue) 14:21:10 編集(投稿者)
現在、マルチウィンドウシステムを構築中で、Datagridviewでクリックした時のイベント処理で困っております。
構成として・・・
メイン画面
└コンポーネント
└Bindingsource
└Bindingnavigatorを実装したフォーム
└DataGridViewを実装したフォーム
となっております。
現象として・・・
@DataGridViewで行をクリック
Aカレント行変更(BindingSource.CurrentChanged)イベントが発生します。
B(BindingSource.CurrentChanged)イベント処理内で元の行に戻す処理をします。
Bindingsource.Position = カレント行変更直前の行位置
CBindingsource.Positionは元の場所に戻ります。
DDataGridView.CurrentRow.Indexは変化なし。(クリック位置のまんまだったりします)
そこで・・・
”Bindingsource DataGridView カレント 同期”で、Googleって見たのですが、
「Bidingsourceは、DataGridView等の複数のコントロールでデータセットを共有する物」
といった内容ばかりで、なかなか見当たりません。
よく見かける様な処理と思いますが・・・
皆さんはどの様に回避または対応されて居られるのでしょうか?
ご教授の程、をお願い致します。