2010-12-17 18 views
-1

DataGridView内の1つの列の編集のみを許可したいが、行内の項目をダブルクリックすることができ、CellBeginEditが起動すると強制的にmy列。私はこのことによって開始:DataGridViewを1つの列に強制的に編集する

Private Sub dgvCaptions_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles dgvCaptions.CellBeginEdit 
     If e.ColumnIndex <> COL_CAPTION Then 
      e.Cancel = True 
      dgvCaptions.ClearSelection() 
      dgvCaptions.Rows(e.RowIndex).Cells(COL_CAPTION).Selected = True 
      dgvCaptions.BeginEdit(False) 
     End If 
    End Sub 

をしかしので、これはにBeginEdit(偽)の行でエラーがスローされます「がにBeginEdit関数への再入可能呼び出しにつながるため、操作は有効ではありません。」もちろんそれはやりますが、それは私が望むものです。これを行う別の方法がありますか?

答えて

0

を呼び出して、あなたの編集可能なセルにセルを選択し、double clickハンドラのセットでは、私は、このリンクは有用であることが判明し、私のニーズのためにそれを適応:

Delegate Sub SetColumnIndex(ByVal i As Integer) 

    Private Sub dataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) 
     If Me.dataGridView1.CurrentCell.ColumnIndex <> Me.dataGridView1.Columns.Count - 1 Then 
      Dim nextindex As Integer = Math.Min(Me.dataGridView1.Columns.Count - 1, Me.dataGridView1.CurrentCell.ColumnIndex + 1) 
      Dim method As New SetColumnIndex(AddressOf Mymethod) 
      Me.dataGridView1.BeginInvoke(method, nextindex) 
     End If 
    End Sub 

    Private Sub Mymethod(ByVal columnIndex As Integer) 
     Me.dataGridView1.CurrentCell = Me.dataGridView1.CurrentRow.Cells(columnIndex) 
     Me.dataGridView1.BeginEdit(True) 
    End Sub 

MSDN Forum Credit

1

CellBeginEditイベントを処理する代わりに、他のセルを読み取り専用にして処理してみてください。double clickイベント。最後にBeginEdit

+0

私はしないでくださいダブルクリックで編集したいだけですが、F2キーを押すか、行内の項目をダブルクリックすると、その行の1つの列だけを編集することができます –

関連する問題