completely new to datagridviews

Will.i.am

New member
Joined
Mar 15, 2010
Messages
3
Programming Experience
Beginner
Hey everyone, i have used this site many times to help with random VB issues, but never posted, so this is my first post :)

Anyway, i have some issues with using a datagridview to list contents from a database table.

I can get it to list the table OK, and everything there works fine, but i can't wok out how if it is even possable to diclare the data inside the selected row, output it onto a diffrent form then allow the user to edit the information and overwrite the row in the database.

Also using a binding source to queery the data from the table.

Currently i have:

VB.NET:
        Dim FName As String
        Dim LName As String
        Dim ID As String
        Dim Search As BindingSource

        FName = txtFName.Text
        LName = txtLName.Text
        ID = txtID.Text


        Search = New BindingSource
        Search.DataSource = GeneralDataSet.Customers

        dgvSearch.DataSource = Search

        Search.Filter = "LastName" = LName

But i will be honest, that is a complete guess, i really don't have a clue with it..

I would appreciate and advice :)

Thanks, Will.
 
I would recommend taking a look at this series: Forms over Data Video Series

If you're going to use the Filter method on the Binding source the syntax would look like:

VB.NET:
Search.Filter = "LastName = " & LName

Regardless of how you get your row that you want to edit it looks like you want to pass that row to a separate form and modify it. jmcilhinney has an excellent writeup here explaining how to do just that. [.NET 2.0+] Update Grid Row in Dialogue - VBForums
 
I would recommend taking a look at this series: Forms over Data Video Series

If you're going to use the Filter method on the Binding source the syntax would look like:

VB.NET:
Search.Filter = "LastName = " & LName

Regardless of how you get your row that you want to edit it looks like you want to pass that row to a separate form and modify it. jmcilhinney has an excellent writeup here explaining how to do just that. [.NET 2.0+] Update Grid Row in Dialogue - VBForums

Thanks for the reply, however i get an error message: If "x" was entered in the txtLName the error would be: "Cannot find column [x]."

Any ideas?

Thanks

Will.
 
Search.Filter = String.Format("LastName = '{0}'", LName)

ensure lname doesnt contain apostrophes, or replace them with double apostrophes (i think)
 
Note that filter is for temporary restriction on the client, to further refine a search. You wouldnt use this method to search thedatabase. Don't download a million rows from the db and then filter them down to one in the client. Instead write a sql query to return only the one ina million row you actually want.

See DW2 link in my signaute, section Creating a Form to Search Data
 
Thank you very much cjard!

Worked perfectly.

I now have a new problem.. qurrying a table in a databse with the data from a cell in a datagridview.

I tried to use the same formular as you said, however i get the error message: "Cannot perform '=' operation on System.Int32 and System.String" on the fill line of the DGV.

From the previous form i have:

VB.NET:
        IDSearch = dgvSearch.Columns("ID")
        frmExistingJobs.Show()

and in the new form i have:

VB.NET:
        Dim SearchID As DataGridViewColumn
        Dim Jobs As BindingSource

        Jobs = New BindingSource
        SearchID = frmsearch.IDSearch
        Jobs.DataSource = GeneralDataSet1.Services

        Jobs.Filter = String.Format("ID = '{0}'", SearchID)

        Me.ServicesTableAdapter.Fill(Me.GeneralDataSet1.Services)
 
Last edited:
Back
Top