Bound DataGridView not updating to display information + sorting issues

后端 未结 2 1488
情话喂你
情话喂你 2021-01-24 04:36

I have a bound DataGridView1 and several bound TextBoxes and DateTimePickers.

Everything is working well, except when I try to accomplish these two things in conjunction

2条回答
  •  轮回少年
    2021-01-24 05:15

    DGV shows edited value after cell validation and this seems to be an issue around DGV. In order to do that (considered as workaround) you can simulate/force by yourself your grid validation (calling the method below) after you have setted the value on your cell:

    Private Sub SimulateDGVValidation()
    
        Try
    
            Dim currentCell As DataGridViewCell = Me.DataGridView1.CurrentCell
    
            If (currentCell) IsNot Nothing Then
                Dim c As Integer = IIf(currentCell.ColumnIndex > 1, currentCell.ColumnIndex - 1, 1)
                Me.DataGridView1.CurrentCell = Me.DataGridView1(c, currentCell.RowIndex)
            Else
                Me.DataGridView1.CurrentCell = Me.DataGridView1(0, 0)
            End If
    
    
            Application.DoEvents()
    
            'Return in the initial cell 
            If (currentCell) IsNot Nothing Then
                Me.DataGridView1.CurrentCell = currentCell
            End If
    
    
        Catch ex As Exception
            Console.WriteLine(ex.ToString)
        End Try
    
    End Sub
    

提交回复
热议问题