Hi,
Appeciate some help please.
I have a datagridview which I have added a button into.
When the grid is unfiltered the button works fine but when I apply the filter it does not appear to work.
Is there any way I can get the button to work whilst filtered!
Code so far
Code:Dim dt As DataTable Dim bndSourceGrid As New BindingSource() Private Sub frmUserMaint_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load dt = Me.Tbl_UsersTableAdapter.GetUsers bndSourceGrid.DataSource = dt DataGridView1.DataSource = bndSourceGrid ' setup binding source With DataGridView1 Dim btnEdit As New DataGridViewButtonColumn() .Columns.Add(btnEdit) btnEdit.HeaderText = "Edit" btnEdit.Text = "Edit" btnEdit.Name = "btnEdit" btnEdit.FlatStyle = FlatStyle.Flat btnEdit.UseColumnTextForButtonValue = True End With End Sub Private Sub DataGridView1_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick Dim colName As String = DataGridView1.Columns(e.ColumnIndex).Name Dim User As Integer Dim GroupName As String Me.Tbl_UserGroupsTableAdapter.FillbyID(Me.DataSet1.tbl_UserGroups, CInt(DataGridView1.Rows(e.RowIndex).Cells("UserGroupID").Value)) If Me.DataSet1.tbl_UserGroups.Count > 0 Then Dim row As DataRow = DataSet1.tbl_UserGroups.Rows(0) GroupName = row.Item("UserGroupName").ToString End If If e.RowIndex >= 0 Then User = CInt(DataGridView1.Rows(e.RowIndex).Cells("ID").Value) With DataGridView1 If colName = "btnEdit" Then txtName.Text = .Rows(e.RowIndex).Cells("UserName").Value End If End With End If End Sub Private Sub txtSearchID_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSearchID.TextChanged bndSourceGrid.Filter = String.Format("{0} LIKE '%{1}%'", "UserID", txtSearchID.Text) End Sub Private Sub txtSearchID_Validated(sender As System.Object, e As System.EventArgs) Handles txtSearchID.Validated If txtSearchID.Text = String.Empty Then bndSourceGrid.RemoveFilter() Else bndSourceGrid.Filter = String.Format("{0} = '{1}'", "UserID", txtSearchID.Text) End If End Sub




Reply With Quote
