アプリ版:「スタンプのみでお礼する」機能のリリースについて

書き方法で右クリックにて セルの選択をしてコンテキストメニューを表示させて
cellに追加文字を追加させることをしてます。

Multiselect=false で 選択はfullselectrow です。
データバインドでdatatableをバインドさせてます。

.CurrentRowが前のままになってしまって データがずれてしまいます。
どのようにすれば currentrowがきちんと取得できるでしょうか?



Private Sub DataGridView1_CellMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDown

If e.Button = Windows.Forms.MouseButtons.Right Then
DataGridView1.ClearSelection()
If e.RowIndex < 0 Then Exit Sub
DataGridView1.Rows(e.RowIndex).Selected = True

End If

End Sub

A 回答 (1件)

.CurrentRow と .Selected された行って別物ということですね。


.CurrentRow はカーソル ( 入力フォーカス ) がある行で、
.Selected はカーソルのある/なしにかかわらず選択 ( 反転表示 ) されている行のことです。
.CurrentRow を使用せずに、e.RowIndex、e.ColumnIndex を使用すればいいんじゃないか、と思ったりするのですが、.CurrentRow をクリックされた行にするのであれば、↓のようにすればできます。

If e.Button = Windows.Forms.MouseButtons.Right Then

DataGridView1.ClearSelection()
If e.RowIndex < 0 Then Exit Sub

With DataGridView1

Dim col As Integer

If e.ColumnIndex < 0 Then
col = 0
Else
col = e.ColumnIndex
End If

.CurrentCell = .Rows(e.RowIndex).Cells(col)

.Rows(e.RowIndex).Selected = True

End With

End If
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!