Question Binding control

gate7cy

Well-known member
Joined
May 11, 2009
Messages
119
Programming Experience
3-5
I have a winform (VB 08) with some datagridviews, databinded textboxes, etc ( Access 07 database ).
In the form I use this search I have some databinded textboxes, etc. After I changed my fill from this :
VB.NET:
Expand Collapse Copy
Me.AllServicesTableAdapter.search(Me.Database2DataSet.AllServices, search1, search2)

to this

VB.NET:
Expand Collapse Copy
Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\Serverjde\jde\Database0.accdb;Persist Security Info=False;")

        Dim search1 As String = Me.TextBox3.Text
        Dim search2 As String = Me.TextBox1.Text
Try
                
conn.Open()

                Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from AllServices where 'search1' = '" & search2 & "'", conn)

                Dim ds As Database2DataSet = New Database2DataSet
                ' fill dataset 
                da.Fill(ds, "AllServices")

                ' Attach DataSet to DataGrid 
                AllServicesDataGridView.DataSource = ds.Tables("AllServices")


            Catch ex As Exception
                System.Windows.Forms.MessageBox.Show(ex.Message)
            End Try

these databinded objects stop functioning. What I mean is that those objects where changing values reflecting the current selected row in the datagridviews I have on the form. Now they will work the first time and that is it. Is it due to the dataadapter I created? The only change came from the different fill methods I use now.Can anyone help pls....? Thanks for the replies
 
Your problem is because your DataGridView is bound to a different datasource than your textboxes after you call your search
VB.NET:
Expand Collapse Copy
    Dim ds As Database2DataSet = New Database2DataSet '<=== new DataSet
    ' fill dataset 
    da.Fill(ds, "AllServices")

    ' Attach DataSet to DataGrid 
    AllServicesDataGridView.DataSource = ds.Tables("AllServices")

The first line of this snippet (from your own code) creates a new dataset which is then bound to the DataGridView in the last line.

Without seeing more of your code, it is difficult to be absolutely certain of the solution, but if you used the Data-Wizard to create your controls originally, it should have put a BindingSource component on your form, which both your TextBoxes and DataGridView use, either directly or indirectly. The BindingSource has methods for searching and sorting, so you might want to look at that.

Good Luck! :)
 
Thanks for the reply henry. I have started altering my code so I would not use the binded textboxes. Nevertheless I have not yet found the solution. I understand the problem now that you have showed me. What code would you want to see? The form load event code, ?
 
The Form_Load Code would help, if that is where your data binding is done, otherwise the method or methods where it is.
 
The data binding is done by VS as you drag and drop the fields from the datasource. I did not use any code of my own to bind the controls to the table.
 
Then as I said earlier, there should be a BindingSource component (or more than 1, depending on how you constructed your form), so research The MSDN documentation for BindingSource, particularly the Filter and Find methods.

Use the Find method of the BindingSource that your DataGridView uses as its DataSource.
 
Back
Top