我有一个想要过滤的datagridview。
在datagridview上方,我有第二个单行空过滤器datagridview,列数相同。
当用户键入其中一个单元格时,我想根据过滤器datagridview的填充单元格过滤主数据网格。
在应用过滤器之前,我想在仍在编辑的情况下使用当前单元格文本更新标签。
如何在编辑结束前获取用户更改的文字?
答案 0 :(得分: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