0

datagridviewにいくつかの名前が入力されています。datagridviewの名前を使用して別のデータベースのすべての名前のチェックを実行し、一致が見つかったときに隣接するセルに名前を追加します。これは、文字列比較メソッドによって実現しています。

私の問題は、入力の不一致が原因で、同じ名前の2人がいる場合、一部の名前が適切に判断されないことです。

私が欲しいのは、Datagridviewに存在する名前のいずれかを選択するか、新しい行に名と名前の両方を入力するかをユーザーに選択させることです。これを実現するには、ユーザーがdatagridviewの行の1つをクリックするまでプログラムを待機させます。

この効果を待つ方法はありますか?

ありがとうジョン

4

3 に答える 3

0

ここで何かが足りないのですか、それともDataGridView.Clickイベントに反応したくないですか?次に、DataGridView.SelectedRowsを使用して、行が選択されていることを確認し、選択された行で必要な処理を実行できます。

Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView.Click

End Sub

お役に立てれば

乾杯

于 2010-03-18T09:47:10.097 に答える
0

さて、私はこの問題の回避策を見つけました。それがより良いものの1つであるかどうかわからないので、より良い方法を知りたいです。

    Dim gFlag As Boolean = False
Function MakeChoice(ByVal Name As String, ByVal i As Integer)

    Dim flag As Boolean
    Dim C1, C2 As MsgBoxResult
    Dim msg As String = "Select a row and press Ok to add a value to that row " & _
                        "Or Press cancel to Add a New Row"

    'Displays and Records Users Input
    C1 = MessageBox.Show(msg, Name, MessageBoxButtons.OKCancel)

    Select Case C1

        'If user wants to choose one of the rows in datagridview
        Case MsgBoxResult.Ok
            flag = True

            'Scrolls to the row with closest match
            dgv1.FirstDisplayedScrollingRowIndex = i
            dgv1.Focus()

            'Waits for gFlag to be True
            Do
                If gFlag = True Then
                    Exit Do
                End If
            Loop

            'Resets gflag to previous state ie; False in case this function
            'is accessed recursively
            gFlag = False

            'Finds the index of selected Row
            i = dgv1.CurrentRow.Index

            'Displays the message just to make sure user has chosen a right row just-in-case
            C2 = MsgBox("Are you sure that """ & Name & """ is same as  """ & dgv1.Rows(i).Cells(1).Value _
               & "", MsgBoxStyle.OkCancel)
            Select Case C2

                'If user confirms then return flag to be true and hence _
                'add the value in the selected row of datagridview
                Case MsgBoxResult.Ok
                    flag = True

                    'If selected row is not same as the desired row then go through a recursive
                    'Loop
                Case MsgBoxResult.Cancel
                    flag = MakeChoice(Name, i)
            End Select

            'If C1 = Cancel then add set flag to False ie add the value to a new row
        Case MsgBoxResult.Cancel
            flag = False

    End Select

    Return flag
End Function

Function GridClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgv1.Click
    'I think this part is self explanatory
    gFlag = False
    If sender.ToString = "System.Windows.Forms.DataGridView" Then
        gFlag = True
    End If
    Return gFlag
End Function

後から考えると、それほど大きな問題ではなかったと思いますが、それが誰かに役立つことを願っています。それをより良くするための提案を探しているでしょう。ありがとうジョン

于 2010-03-18T09:22:04.927 に答える
0

それが私がやっていることですが、gFlag値を返すようにしたかったので、関数として使用しています。後で、gFlag をグローバル変数として宣言することにしましたが、関数宣言で永続化しました。乾杯

于 2010-03-18T18:18:11.327 に答える