Hey guys i need some help on how to create a connection of a relationship between two forms...for example I have a DataGridView on another form....with a search button.. if i click the search button another window will pop out with a text box lable "Look For:" and a combobox "Look In:" that contains all the field names in that particular datagridview.

Recommended Answers

All 7 Replies

By the way i am using MySQL as a database.

can you please repharse your question i dont get you , well what i understand is that you want to filter your datagrid by selecting values from 2nd form ?

Regards

Yes..for Example I have a Datagridview on the Form1 with Search button then on the 2nd form has the textbox and combo box........so when i click the search button (form1) the form 2 will apear with the Textbox and a Combo box the combo box will be filled with all the field names in the form1 data table.

Here is a simple example:
Form 1

Sub ShowDetials()
    dim RecordID as integer
    dim DT as datatable     
    Dim DS as new dataset
    Dim DA as new OleDBDataAdapter
    dim mCmd as new OleDbCommand
    dim DetialsForm as new Form2
    'I will assume your datagrid has row selection and the primary key of the record is in cell 0
    dim Conn as new OleDbConnection(Connectionstring)
    conn.open 
    IF MyDatagridView.SelectedRows.Count>0 then
        RecordID = MyDatagridView.SelectedRows(0).Cell(0).value

        mCmd.Connection = Conn
        mCmd.CommandType = CommandType.Text
        mCmd.Text ="SELECT * FROM MyTable WHERE(MyID =" &RecordID &")"
        DA.SelectCommand = mCmd
        DA.Fill(DS)
        DT = DS.Tables(0)
        'now for the putting stuff on to the other form...
        'For speed I'll just stick evrything into a datagridview
        DetailsForm.DataGridView1.Datasource = DT
        DetailsForm.Show()
     end if
End sub

sir can you check the picture that i provided on the link also do i put this code on the search button?

I chaned the forms so its workign fine thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.