0

我有一个要过滤的datagridview。

在 datagridview 上方,我有第二个具有相同列数的单行空过滤器 datagridview。

当用户输入其中一个单元格时,我想根据过滤器 datagridview 的填充单元格过滤主 datagridview。

在应用过滤器之前,我想在当前单元格文本仍在编辑时更新标签。

如何在编辑结束前获取用户更改的文本?

4

1 回答 1

0

已解决 - 使用 c.EditedFormattedValue.ToString

Private Sub dgvFilter_EditingControlShowing(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) _
    Handles dgvFilter.EditingControlShowing

    Dim tb As TextBox = TryCast(e.Control, TextBox)

    If (tb IsNot Nothing) Then
        RemoveHandler tb.KeyUp, AddressOf tb_KeyUp
        AddHandler tb.KeyUp, AddressOf tb_KeyUp

        'RemoveHandler tb.KeyDown, AddressOf tb_KeyDown
        'AddHandler tb.KeyDown, AddressOf tb_KeyDown
    End If

End Sub


Private Sub tb_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)

    Dim c As DataGridViewCell = dgvFilter.CurrentCell
    Dim s As String = c.EditedFormattedValue.ToString
    Dim totalFilter As String

    lblKeyCode.Text = e.KeyCode

    'If e.KeyCode <> Keys.Down Then

    cellName = dgvFilter.Columns(dgvFilter.CurrentCell.ColumnIndex).Name

    cellFilter = "[" & cellName & "] LIKE '" & s & "%'"

    'get the filter (other columns plus current column)
    totalFilter = FilterString(dgvFilter, cellFilter)
    Me.txtFilter.Text = totalFilter

    'apply the filter
    Me.lookupDataTable.DefaultView.RowFilter = totalFilter
    'Else
    'dgv.Focus()
    'End If

End Sub
于 2012-08-13T17:34:34.653 回答