Help with control binding

Hi All

I'm a bit of a newbie at vb.net and was hoping someone can help me with a problem that has me stumped. I'm sure the solution is quite simple but I can't see it.

I have simple sql express database that has two small tables. Table 1 contains a foreign key from table 2.

I have a form where the controls on it are bound to table 1. For the control that displays the field that contains the foreign key from table 2 I want to use a combo box that displays the corresponding value from table 2 instead of the value of the foreign key and allows the user to select one of the other values from table 2. When a new record is saved or a change to an existing record the value of the foreign key from this combo box should be stored in table 1.

Hope my description isn't too confusing and would appreciate any assistance.

Regards

ilr



Answer this question

Help with control binding

  • raoul85

    hi,

    with bindingsources its very simple , add a new bindingSource to your form go to bindingsource2 properties make its datasource = yourdataset, datamember = "table2" , i guess you will need to add table adapter to your table 2 as well

    then go to your first bindingsource properties and edit it make teh datasource = bindingsource2, and datamember = the relationbetween the 2 tables

    then add combobox and bound it to your bindingsource 2 then run your program

    best regards



  • Abe

    Thanks Shakalama

    That was very helpful and is a big improvement on what I had.

    I now have the problem that when I change the value of the combo box it changes the current record instead of changing the value of the field in table 1. I'm not sure if this is because of the way I've set up my database or they way I am using the binding source components.

    Any ideas

    Regards

    ilr


  • Denny Boynton

    hi,

    its the way that you useing hte binding source sorry i didn't understand your question correct

    i don't know anyway to make the combobox lookup to the higher table, but i do that by adding a insertnewrecord form or editingrecord form a in that button event handler


    'if you want to add record

    Dim dr As MydatasetName.MytableNameRow' is the dataset name in your solution explorer

    dr = Me.MydatasetinstanceName.MytableName.NewMytableNameRow ' is the dataset instance name in your form

    dr.columnName = textbox.text or combobox.selecteditem you are ree

    Me.Mydatasetinstancename.Mytablename.AddmytablenameRow(dr)
    'to edit row

    Dim editdr As DataRow
    editdr =
    Me.MydatasetinstanceName.MytableName.Rows.Find("columnname = value") ' use the table key value(id)
    editdr.BeginEdit()
    editdr(
    "columnname") = "value"

    editdr.EndEdit()


    i use this way and i add combobox and textbox and bind them to 2 different tables and don't make them depend on each other

    also make a property in your second form for the dataset, absolute beginners videos have a good example about that (creat channels form)

    hope this helps



  • Help with control binding