|
-
Jun 27th, 2017, 09:12 AM
#1
Thread Starter
Lively Member
Datagridview button not working when use databoundfilter
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
-
Jun 27th, 2017, 09:18 AM
#2
Re: Datagridview button not working when use databoundfilter
 Originally Posted by jpskiller
it does not appear to work.
Perhaps you could explain what that actually means? What EXACTLY do you expect to happen and what EXACTLY does actually happen?
-
Jun 27th, 2017, 09:20 AM
#3
Re: Datagridview button not working when use databoundfilter
Also, have you actually debugged (i.e. set a breakpoint and stepped through the code) the CellContentClick event handler to see exactly where the path of execution and/or the application state (i.e. values of variables, etc.) isn't as expected? If not, you should do that now. If so, you should explain what you found.
-
Jun 27th, 2017, 09:37 AM
#4
Thread Starter
Lively Member
Re: Datagridview button not working when use databoundfilter
Hi, sorry.
When the grid is unfiltered then it fires the DataGridView1_CellContentClick and executes the code as expected.
If the grid is filtered then when I click on button, then DataGridView1_CellContentClick is not entered and does not execute any code but the datagrid just completely clears itself, until I remove the filter then grid fills back as normal.
-
Jun 27th, 2017, 09:46 AM
#5
Re: Datagridview button not working when use databoundfilter
Why are you filtering in both the TextChanged and Validated event handlers of that TextBox and doing it differently in each place? That doesn't make sense. I'm guessing that your issue is that Validated event handler, which will be executed when the TextBox loses focus, which would happen when clicking on a button in the grid.
-
Jun 27th, 2017, 10:28 AM
#6
Thread Starter
Lively Member
Re: Datagridview button not working when use databoundfilter
 Originally Posted by jmcilhinney
Why are you filtering in both the TextChanged and Validated event handlers of that TextBox and doing it differently in each place? That doesn't make sense. I'm guessing that your issue is that Validated event handler, which will be executed when the TextBox loses focus, which would happen when clicking on a button in the grid.
Your absolutely right it was the text box validate, I had forgotten to remove It, it was there because I was experimenting with text change / Validate methods.
Thank you.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|